lib/css_parser/parser.rb in css_parser-1.2.5 vs lib/css_parser/parser.rb in css_parser-1.2.6
- old
+ new
@@ -117,11 +117,11 @@
end
next unless options[:only_media_types].include?(:all) or media_types.length < 1 or (media_types & options[:only_media_types]).length > 0
import_path = import_rule[0].to_s.gsub(/['"]*/, '').strip
-
+
if options[:base_uri]
import_uri = Addressable::URI.parse(options[:base_uri].to_s) + Addressable::URI.parse(import_path)
load_uri!(import_uri, options[:base_uri], media_types)
elsif options[:base_dir]
load_file!(import_path, options[:base_dir], media_types)
@@ -328,21 +328,19 @@
opts.merge!(options)
else
opts[:base_uri] = options if options.is_a? String
opts[:media_types] = deprecated if deprecated
end
-
-
+
if uri.scheme == 'file' or uri.scheme.nil?
uri.path = File.expand_path(uri.path)
uri.scheme = 'file'
end
opts[:base_uri] = uri if opts[:base_uri].nil?
src, charset = read_remote_file(uri)
-
if src
add_block!(src, opts)
end
end
@@ -421,11 +419,12 @@
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
else
http = Net::HTTP.new(uri.host, uri.port)
end
- res, src = http.get(uri.path, {'User-Agent' => USER_AGENT, 'Accept-Encoding' => 'gzip'})
+ res = http.get(uri.path, {'User-Agent' => USER_AGENT, 'Accept-Encoding' => 'gzip'})
+ src = res.body
charset = fh.respond_to?(:charset) ? fh.charset : 'utf-8'
if res.code.to_i >= 400
raise RemoteFileError if @options[:io_exceptions]
return '', nil
@@ -440,11 +439,15 @@
src = io.inflate(res.body)
end
end
if charset
- ic = Iconv.new('UTF-8//IGNORE', charset)
- src = ic.iconv(src)
+ if String.method_defined?(:encode)
+ src.encode!('UTF-8', charset)
+ else
+ ic = Iconv.new('UTF-8//IGNORE', charset)
+ src = ic.iconv(src)
+ end
end
rescue
raise RemoteFileError if @options[:io_exceptions]
return nil, nil
end