mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix route params using reserved keywords:
- In #39534, `Routing::RouteSet#generate_extras` (which get called) by ActionController::TestCase now go through `path_for` which strips out all key in the options hash that have the same name as the ones defined in `RESERVED_OPTIONS`.
This commit is contained in:
parent
054b54e866
commit
7dc4c4365c
2 changed files with 9 additions and 5 deletions
|
@ -766,7 +766,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
route_name = options.delete :use_route
|
route_name = options.delete :use_route
|
||||||
path = path_for(options, route_name)
|
path = path_for(options, route_name, [])
|
||||||
|
|
||||||
uri = URI.parse(path)
|
uri = URI.parse(path)
|
||||||
params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys
|
params = Rack::Utils.parse_nested_query(uri.query).symbolize_keys
|
||||||
|
@ -794,12 +794,12 @@ module ActionDispatch
|
||||||
options.delete(:relative_url_root) || relative_url_root
|
options.delete(:relative_url_root) || relative_url_root
|
||||||
end
|
end
|
||||||
|
|
||||||
def path_for(options, route_name = nil)
|
def path_for(options, route_name = nil, reserved = RESERVED_OPTIONS)
|
||||||
url_for(options, route_name, PATH)
|
url_for(options, route_name, PATH, nil, reserved)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The +options+ argument must be a hash whose keys are *symbols*.
|
# The +options+ argument must be a hash whose keys are *symbols*.
|
||||||
def url_for(options, route_name = nil, url_strategy = UNKNOWN, method_name = nil)
|
def url_for(options, route_name = nil, url_strategy = UNKNOWN, method_name = nil, reserved = RESERVED_OPTIONS)
|
||||||
options = default_url_options.merge options
|
options = default_url_options.merge options
|
||||||
|
|
||||||
user = password = nil
|
user = password = nil
|
||||||
|
@ -819,7 +819,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
path_options = options.dup
|
path_options = options.dup
|
||||||
RESERVED_OPTIONS.each { |ro| path_options.delete ro }
|
reserved.each { |ro| path_options.delete ro }
|
||||||
|
|
||||||
route_with_params = generate(route_name, path_options, recall)
|
route_with_params = generate(route_name, path_options, recall)
|
||||||
path = route_with_params.path(method_name)
|
path = route_with_params.path(method_name)
|
||||||
|
|
|
@ -2085,6 +2085,10 @@ class RackMountIntegrationTests < ActiveSupport::TestCase
|
||||||
params = { controller: "people", action: "create", person: { name: "Josh" } }
|
params = { controller: "people", action: "create", person: { name: "Josh" } }
|
||||||
assert_equal [:person], @routes.extra_keys(params)
|
assert_equal [:person], @routes.extra_keys(params)
|
||||||
assert_equal({ controller: "people", action: "create", person: { name: "Josh" } }, params)
|
assert_equal({ controller: "people", action: "create", person: { name: "Josh" } }, params)
|
||||||
|
|
||||||
|
params = { controller: "people", action: "create", domain: { foo: "Josh" } }
|
||||||
|
assert_equal [:domain], @routes.extra_keys(params)
|
||||||
|
assert_equal({ controller: "people", action: "create", domain: { foo: "Josh" } }, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_unicode_path
|
def test_unicode_path
|
||||||
|
|
Loading…
Reference in a new issue