Skip to content

Commit

Permalink
Merge pull request #812 from yahonda/uri_rfc3986_parser_escape_and_un…
Browse files Browse the repository at this point in the history
…escape_are_oboleted

Address `warning: URI::RFC3986_PARSER` warnings against ruby 3.4.0dev
  • Loading branch information
yahonda authored Feb 25, 2025
2 parents 19b056c + 9386ae4 commit 2fe13f2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/sprockets/uri_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2fe13f2

Please sign in to comment.