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