diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index 85da4a1d6..03e0f19cc 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -21,6 +21,9 @@ module Sprockets module URIUtils extend self + URI_PARSER = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::Generic::DEFAULT_PARSER + private_constant :URI_PARSER + # Internal: Parse URI into component parts. # # uri - String uri @@ -45,7 +48,7 @@ def join_uri(scheme, userinfo, host, port, registry, path, opaque, query, fragme def split_file_uri(uri) scheme, _, host, _, _, path, _, query, _ = URI.split(uri) - path = URI::Generic::DEFAULT_PARSER.unescape(path) + path = URI_PARSER.unescape(path) path.force_encoding(Encoding::UTF_8) # Hack for parsing Windows "/C:/Users/IEUser" paths @@ -63,7 +66,7 @@ def join_file_uri(scheme, host, path, query) str = +"#{scheme}://" str << host if host path = "/#{path}" unless path.start_with?("/".freeze) - str << URI::Generic::DEFAULT_PARSER.escape(path) + str << URI_PARSER.escape(path) str << "?#{query}" if query str end @@ -162,7 +165,7 @@ def encode_uri_query_params(params) when Integer query << "#{key}=#{value}" when String, Symbol - query << "#{key}=#{URI::Generic::DEFAULT_PARSER.escape(value.to_s)}" + query << "#{key}=#{URI_PARSER.escape(value.to_s)}" when TrueClass query << "#{key}" when FalseClass, NilClass @@ -182,7 +185,7 @@ def encode_uri_query_params(params) def parse_uri_query_params(query) query.to_s.split('&'.freeze).reduce({}) do |h, p| k, v = p.split('='.freeze, 2) - v = URI::Generic::DEFAULT_PARSER.unescape(v) if v + v = URI_PARSER.unescape(v) if v h[k.to_sym] = v || true h end