@@ -21,6 +21,9 @@ module Sprockets
21
21
module URIUtils
22
22
extend self
23
23
24
+ URI_PARSER = defined? ( URI ::RFC2396_PARSER ) ? URI ::RFC2396_PARSER : URI ::Generic ::DEFAULT_PARSER
25
+ private_constant :URI_PARSER
26
+
24
27
# Internal: Parse URI into component parts.
25
28
#
26
29
# uri - String uri
@@ -45,7 +48,7 @@ def join_uri(scheme, userinfo, host, port, registry, path, opaque, query, fragme
45
48
def split_file_uri ( uri )
46
49
scheme , _ , host , _ , _ , path , _ , query , _ = URI . split ( uri )
47
50
48
- path = URI :: Generic :: DEFAULT_PARSER . unescape ( path )
51
+ path = URI_PARSER . unescape ( path )
49
52
path . force_encoding ( Encoding ::UTF_8 )
50
53
51
54
# Hack for parsing Windows "/C:/Users/IEUser" paths
@@ -63,7 +66,7 @@ def join_file_uri(scheme, host, path, query)
63
66
str = +"#{ scheme } ://"
64
67
str << host if host
65
68
path = "/#{ path } " unless path . start_with? ( "/" . freeze )
66
- str << URI :: Generic :: DEFAULT_PARSER . escape ( path )
69
+ str << URI_PARSER . escape ( path )
67
70
str << "?#{ query } " if query
68
71
str
69
72
end
@@ -162,7 +165,7 @@ def encode_uri_query_params(params)
162
165
when Integer
163
166
query << "#{ key } =#{ value } "
164
167
when String , Symbol
165
- query << "#{ key } =#{ URI :: Generic :: DEFAULT_PARSER . escape ( value . to_s ) } "
168
+ query << "#{ key } =#{ URI_PARSER . escape ( value . to_s ) } "
166
169
when TrueClass
167
170
query << "#{ key } "
168
171
when FalseClass , NilClass
@@ -182,7 +185,7 @@ def encode_uri_query_params(params)
182
185
def parse_uri_query_params ( query )
183
186
query . to_s . split ( '&' . freeze ) . reduce ( { } ) do |h , p |
184
187
k , v = p . split ( '=' . freeze , 2 )
185
- v = URI :: Generic :: DEFAULT_PARSER . unescape ( v ) if v
188
+ v = URI_PARSER . unescape ( v ) if v
186
189
h [ k . to_sym ] = v || true
187
190
h
188
191
end
0 commit comments