Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32ff9d7

Browse files
yahondabyroot
authored andcommitted
Use URI::RFC2396_PARSER instead of URI::DEFAULT_PARSER
Ruby 3.4 changes `URI::DEFAULT_PARSER` to `URI::RFC3986_Parser` and deprecates `URI::RFC3986_PARSER.make_regexp`,`URI::RFC3986_PARSER.escape`, `URI::RFC3986_PARSER.unescape` and `URI::RFC3986_PARSER.extract`. uri v0.12.2 for Ruby 3.2/3.1 and v0.13.1 for Ruby 3.3 adds `URI::RFC2396_PARSER`. As of right now there is no way to use uri v0.12.2 for Ruby 3.2/3.1 and v0.13.1 for Ruby 3.3, This commit uses v0.13.1 or higher version for all supported Ruby versions by Rails main branch. It also reverts rails#52682 because the original issue has been resolved. Refer to following URL for the backgrond of this change: - URI::Generic should use URI::RFC3986_PARSER instead of URI::DEFAULT_PARSER https://bugs.ruby-lang.org/issues/19266 - Use RFC3986_Parser by default ruby/uri#107 - Warn compatibility methods in RFC3986_PARSER ruby/uri#114 - Also warn URI::RFC3986_PARSER.extract ruby/uri#121 - Define RFC2396_PARSER for Ruby 3.3 ruby/uri#119 - Define RFC2396_PARSER for Ruby 3.2 and 3.1 ruby/uri#120
1 parent 89ce9f6 commit 32ff9d7

File tree

9 files changed

+12
-12
lines changed

9 files changed

+12
-12
lines changed

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
@@ -2025,7 +2025,7 @@ def add_route(action, controller, options, _path, to, via, formatted, anchor, op
20252025
name_for_action(options.delete(:as), action)
20262026
end
20272027

2028-
path = Mapping.normalize_path URI::DEFAULT_PARSER.escape(path), formatted
2028+
path = Mapping.normalize_path URI::RFC2396_PARSER.escape(path), formatted
20292029
ast = Journey::Parser.parse path
20302030

20312031
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
@@ -917,7 +917,7 @@ def recognize_path_with_request(req, path, extras, raise_on_missing: true)
917917
params.each do |key, value|
918918
if value.is_a?(String)
919919
value = value.dup.force_encoding(Encoding::BINARY)
920-
params[key] = URI::DEFAULT_PARSER.unescape(value)
920+
params[key] = URI::RFC2396_PARSER.unescape(value)
921921
end
922922
end
923923
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.

railties/lib/rails/info_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def properties
2020

2121
def routes
2222
if query = params[:query]
23-
query = URI::DEFAULT_PARSER.escape query
23+
query = URI::RFC2396_PARSER.escape query
2424

2525
render json: {
2626
exact: matching_routes(query: query, exact_match: true),
@@ -53,7 +53,7 @@ def matching_routes(query:, exact_match:)
5353
match ||= (query === route_wrapper.verb)
5454

5555
unless match
56-
controller_action = URI::DEFAULT_PARSER.escape(route_wrapper.reqs)
56+
controller_action = URI::RFC2396_PARSER.escape(route_wrapper.reqs)
5757
match = exact_match ? (query === controller_action) : controller_action.include?(query)
5858
end
5959

railties/test/application/assets_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
324324
# Load app env
325325
app "development"
326326

327-
get "/assets/#{URI::DEFAULT_PARSER.escape(asset_path)}"
327+
get "/assets/#{URI::RFC2396_PARSER.escape(asset_path)}"
328328
assert_match "not an image really", last_response.body
329329
assert_file_exists("#{app_path}/public/assets/#{asset_path}")
330330
end

0 commit comments

Comments
 (0)