Skip to content

Commit

Permalink
use symbol keys for path_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed May 22, 2014
1 parent 0e7e4f7 commit 925bd97
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/metal/url_for.rb
Expand Up @@ -27,7 +27,7 @@ def url_options
:host => request.host,
:port => request.optional_port,
:protocol => request.protocol,
:_recall => request.symbolized_path_parameters
:_recall => request.path_parameters
}.merge(super).freeze

if (same_origin = _routes.equal?(env["action_dispatch.routes".freeze])) ||
Expand Down
10 changes: 5 additions & 5 deletions actionpack/lib/action_controller/test_case.rb
Expand Up @@ -199,7 +199,7 @@ def assign_parameters(routes, controller_path, action, parameters = {})
value = value.dup
end

if extra_keys.include?(key.to_sym)
if extra_keys.include?(key)
non_path_parameters[key] = value
else
if value.is_a?(Array)
Expand All @@ -208,7 +208,7 @@ def assign_parameters(routes, controller_path, action, parameters = {})
value = value.to_param
end

path_parameters[key.to_s] = value
path_parameters[key] = value
end
end

Expand Down Expand Up @@ -583,6 +583,7 @@ def process(action, http_method = 'GET', *args)
end

parameters, session, flash = args
parameters ||= {}

# Ensure that numbers and symbols passed as params are converted to
# proper params, as is the case when engaging rack.
Expand All @@ -601,7 +602,6 @@ def process(action, http_method = 'GET', *args)

@request.env['REQUEST_METHOD'] = http_method

parameters ||= {}
controller_class_name = @controller.class.anonymous? ?
"anonymous" :
@controller.class.controller_path
Expand Down Expand Up @@ -695,7 +695,7 @@ def build_request_uri(action, parameters)
:only_path => true,
:action => action,
:relative_url_root => nil,
:_recall => @request.symbolized_path_parameters)
:_recall => @request.path_parameters)

url, query_string = @routes.url_for(options).split("?", 2)

Expand All @@ -706,7 +706,7 @@ def build_request_uri(action, parameters)
end

def html_format?(parameters)
return true unless parameters.is_a?(Hash)
return true unless parameters.key?(:format)
Mime.fetch(parameters[:format]) { Mime['html'] }.html?
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -47,7 +47,7 @@ def call(env)

private
def constraint_args(constraint, request)
constraint.arity == 1 ? [request] : [request.symbolized_path_parameters, request]
constraint.arity == 1 ? [request] : [request.path_parameters, request]
end
end

Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/routing/redirection.rb
Expand Up @@ -19,13 +19,13 @@ def call(env)

# If any of the path parameters has an invalid encoding then
# raise since it's likely to trigger errors further on.
req.symbolized_path_parameters.each do |key, value|
req.path_parameters.each do |key, value|
unless value.valid_encoding?
raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}"
end
end

uri = URI.parse(path(req.symbolized_path_parameters, req))
uri = URI.parse(path(req.path_parameters, req))

unless uri.host
if relative_path?(uri.path)
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -707,8 +707,8 @@ def recognize_path(path, environment = {})
params[key] = URI.parser.unescape(value)
end
end
old_params = env[::ActionDispatch::Routing::RouteSet::PARAMETERS_KEY]
env[::ActionDispatch::Routing::RouteSet::PARAMETERS_KEY] = (old_params || {}).merge(params)
old_params = req.path_parameters
req.path_parameters = old_params.merge params
dispatcher = route.app
while dispatcher.is_a?(Mapper::Constraints) && dispatcher.matches?(env) do
dispatcher = dispatcher.app
Expand Down
10 changes: 5 additions & 5 deletions actionpack/test/controller/test_case_test.rb
Expand Up @@ -662,7 +662,7 @@ def test_params_passing_doesnt_modify_in_place

def test_id_converted_to_string
get :test_params, :id => 20, :foo => Object.new
assert_kind_of String, @request.path_parameters['id']
assert_kind_of String, @request.path_parameters[:id]
end

def test_array_path_parameter_handled_properly
Expand All @@ -673,17 +673,17 @@ def test_array_path_parameter_handled_properly
end

get :test_params, :path => ['hello', 'world']
assert_equal ['hello', 'world'], @request.path_parameters['path']
assert_equal 'hello/world', @request.path_parameters['path'].to_param
assert_equal ['hello', 'world'], @request.path_parameters[:path]
assert_equal 'hello/world', @request.path_parameters[:path].to_param
end
end

def test_assert_realistic_path_parameters
get :test_params, :id => 20, :foo => Object.new

# All elements of path_parameters should use string keys
# All elements of path_parameters should use Symbol keys
@request.path_parameters.keys.each do |key|
assert_kind_of String, key
assert_kind_of Symbol, key
end
end

Expand Down

0 comments on commit 925bd97

Please sign in to comment.