Skip to content

Commit 2fe13f2

Browse files
authored
Merge pull request #812 from yahonda/uri_rfc3986_parser_escape_and_unescape_are_oboleted
Address `warning: URI::RFC3986_PARSER` warnings against ruby 3.4.0dev
2 parents 19b056c + 9386ae4 commit 2fe13f2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/sprockets/uri_utils.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ module Sprockets
2121
module URIUtils
2222
extend self
2323

24+
URI_PARSER = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::Generic::DEFAULT_PARSER
25+
private_constant :URI_PARSER
26+
2427
# Internal: Parse URI into component parts.
2528
#
2629
# uri - String uri
@@ -45,7 +48,7 @@ def join_uri(scheme, userinfo, host, port, registry, path, opaque, query, fragme
4548
def split_file_uri(uri)
4649
scheme, _, host, _, _, path, _, query, _ = URI.split(uri)
4750

48-
path = URI::Generic::DEFAULT_PARSER.unescape(path)
51+
path = URI_PARSER.unescape(path)
4952
path.force_encoding(Encoding::UTF_8)
5053

5154
# Hack for parsing Windows "/C:/Users/IEUser" paths
@@ -63,7 +66,7 @@ def join_file_uri(scheme, host, path, query)
6366
str = +"#{scheme}://"
6467
str << host if host
6568
path = "/#{path}" unless path.start_with?("/".freeze)
66-
str << URI::Generic::DEFAULT_PARSER.escape(path)
69+
str << URI_PARSER.escape(path)
6770
str << "?#{query}" if query
6871
str
6972
end
@@ -162,7 +165,7 @@ def encode_uri_query_params(params)
162165
when Integer
163166
query << "#{key}=#{value}"
164167
when String, Symbol
165-
query << "#{key}=#{URI::Generic::DEFAULT_PARSER.escape(value.to_s)}"
168+
query << "#{key}=#{URI_PARSER.escape(value.to_s)}"
166169
when TrueClass
167170
query << "#{key}"
168171
when FalseClass, NilClass
@@ -182,7 +185,7 @@ def encode_uri_query_params(params)
182185
def parse_uri_query_params(query)
183186
query.to_s.split('&'.freeze).reduce({}) do |h, p|
184187
k, v = p.split('='.freeze, 2)
185-
v = URI::Generic::DEFAULT_PARSER.unescape(v) if v
188+
v = URI_PARSER.unescape(v) if v
186189
h[k.to_sym] = v || true
187190
h
188191
end

0 commit comments

Comments
 (0)