Commit f412ee94 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Strip UTF-8 BOM when running under Ruby 1.8.

Fixes #427
parent 9e567b6e
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -25,7 +25,13 @@ module JsDuck

      # Reads given filename into string
      def self.read(filename)
        File.open(filename, "r:"+@@encoding) {|f| f.read }
        File.open(filename, "r:"+@@encoding) {|f| self.strip_utf8_bom(f.read) }
      end

      # Takes care of removing UTF-8 byte order mark in Ruby 1.8 which
      # doesn't have built-in encodings support.
      def self.strip_utf8_bom(string)
        string.sub(/\A\xEF\xBB\xBF/, "")
      end

    end