Skip to content

Commit 937ae86

Browse files
authored
Merge pull request rails#52779 from yahonda/use_uri_0_13_1_and_rfc_2396_parser
Use `URI::RFC2396_PARSER` instead of `URI::DEFAULT_PARSER`
2 parents 93e23de + dbf3310 commit 937ae86

File tree

13 files changed

+19
-15
lines changed

13 files changed

+19
-15
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ gem "json", ">= 2.0.0", "!=2.7.0"
3838
# Workaround until Ruby ships with cgi version 0.3.6 or higher.
3939
gem "cgi", ">= 0.3.6", require: false
4040

41+
# Workaround until all supported Ruby versions ship with uri version 0.13.1 or higher.
42+
gem "uri", ">= 0.13.1", require: false
43+
4144
gem "prism"
4245

4346
group :lint do

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ PATH
9696
minitest (>= 5.1)
9797
securerandom (>= 0.3)
9898
tzinfo (~> 2.0, >= 2.0.5)
99+
uri (>= 0.13.1)
99100
rails (8.0.0.alpha)
100101
actioncable (= 8.0.0.alpha)
101102
actionmailbox (= 8.0.0.alpha)
@@ -596,6 +597,7 @@ GEM
596597
concurrent-ruby (~> 1.0)
597598
uber (0.1.0)
598599
unicode-display_width (2.5.0)
600+
uri (0.13.1)
599601
useragent (0.16.10)
600602
w3c_validators (1.3.7)
601603
json (>= 1.8)
@@ -701,6 +703,7 @@ DEPENDENCIES
701703
trilogy (>= 2.7.0)
702704
turbo-rails
703705
tzinfo-data
706+
uri (>= 0.13.1)
704707
useragent
705708
w3c_validators (~> 1.3.6)
706709
wdm (>= 0.1.0)

actionpack/lib/action_dispatch/routing/inspector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def normalize_filter(filter)
101101
{ controller: /#{filter[:controller].underscore.sub(/_?controller\z/, "")}/ }
102102
elsif filter[:grep]
103103
grep_pattern = Regexp.new(filter[:grep])
104-
path = URI::DEFAULT_PARSER.escape(filter[:grep])
104+
path = URI::RFC2396_PARSER.escape(filter[:grep])
105105
normalized_path = ("/" + path).squeeze("/")
106106

107107
{

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ def add_route(action, controller, options, _path, to, via, formatted, anchor, op
20332033
name_for_action(options.delete(:as), action)
20342034
end
20352035

2036-
path = Mapping.normalize_path URI::DEFAULT_PARSER.escape(path), formatted
2036+
path = Mapping.normalize_path URI::RFC2396_PARSER.escape(path), formatted
20372037
ast = Journey::Parser.parse path
20382038

20392039
mapping = Mapping.build(@scope, @set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options)

actionpack/lib/action_dispatch/routing/route_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ def recognize_path_with_request(req, path, extras, raise_on_missing: true)
929929
params.each do |key, value|
930930
if value.is_a?(String)
931931
value = value.dup.force_encoding(Encoding::BINARY)
932-
params[key] = URI::DEFAULT_PARSER.unescape(value)
932+
params[key] = URI::RFC2396_PARSER.unescape(value)
933933
end
934934
end
935935
req.path_parameters = params

actionpack/test/controller/parameter_encoding_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ParameterEncodingTest < ActionController::TestCase
5656
end
5757

5858
test "does not raise an error when passed a param declared as ASCII-8BIT that contains invalid bytes" do
59-
get :test_skip_parameter_encoding, params: { "bar" => URI::DEFAULT_PARSER.escape("bar\xE2baz".b) }
59+
get :test_skip_parameter_encoding, params: { "bar" => URI::RFC2396_PARSER.escape("bar\xE2baz".b) }
6060

6161
assert_response :success
6262
assert_equal "ASCII-8BIT", @response.body

actionpack/test/controller/routing_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,11 +2179,11 @@ def test_extras
21792179
end
21802180

21812181
def test_unicode_path
2182-
assert_equal({ controller: "news", action: "index" }, @routes.recognize_path(URI::DEFAULT_PARSER.escape("こんにちは/世界"), method: :get))
2182+
assert_equal({ controller: "news", action: "index" }, @routes.recognize_path(URI::RFC2396_PARSER.escape("こんにちは/世界"), method: :get))
21832183
end
21842184

21852185
def test_downcased_unicode_path
2186-
assert_equal({ controller: "news", action: "index" }, @routes.recognize_path(URI::DEFAULT_PARSER.escape("こんにちは/世界").downcase, method: :get))
2186+
assert_equal({ controller: "news", action: "index" }, @routes.recognize_path(URI::RFC2396_PARSER.escape("こんにちは/世界").downcase, method: :get))
21872187
end
21882188

21892189
private

actionview/lib/action_view/helpers/url_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,14 +556,14 @@ def current_page?(options = nil, check_parameters: false, **options_as_kwargs)
556556

557557
options ||= options_as_kwargs
558558
check_parameters ||= options.is_a?(Hash) && options.delete(:check_parameters)
559-
url_string = URI::DEFAULT_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY)
559+
url_string = URI::RFC2396_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY)
560560

561561
# We ignore any extra parameters in the request_uri if the
562562
# submitted URL doesn't have any either. This lets the function
563563
# work with things like ?order=asc
564564
# the behavior can be disabled with check_parameters: true
565565
request_uri = url_string.index("?") || check_parameters ? request.fullpath : request.path
566-
request_uri = URI::DEFAULT_PARSER.unescape(request_uri).force_encoding(Encoding::BINARY)
566+
request_uri = URI::RFC2396_PARSER.unescape(request_uri).force_encoding(Encoding::BINARY)
567567

568568
if %r{^\w+://}.match?(url_string)
569569
request_uri = +"#{request.protocol}#{request.host_with_port}#{request_uri}"

activerecord/lib/active_record/database_configurations/connection_url_resolver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def to_hash
4545
attr_reader :uri
4646

4747
def uri_parser
48-
@uri_parser ||= URI::Parser.new
48+
@uri_parser ||= URI::RFC2396_Parser.new
4949
end
5050

5151
# Converts the query parameters of the URI into a hash.

activesupport/activesupport.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ Gem::Specification.new do |s|
4444
s.add_dependency "bigdecimal"
4545
s.add_dependency "logger", ">= 1.4.2"
4646
s.add_dependency "securerandom", ">= 0.3"
47+
s.add_dependency "uri", ">= 0.13.1"
4748
end

0 commit comments

Comments
 (0)