Skip to content

Commit

Permalink
Ensure routing generator works with non-string keys. [#172 state:reso…
Browse files Browse the repository at this point in the history
…lved]

Make sure that (with recent correction to globbed parameter escaping) non-string
values can still be passed route generation helpers for globbed route segments.

For example, foo_path([1, 2, 3]) should still work for a route like map.foo "*globbed"
by implicitely calling to_s on the Fixnums.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
Sven Fuchs authored and lifo committed May 16, 2008
1 parent 77f873a commit 345f030
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/routing/segments.rb
Expand Up @@ -249,7 +249,7 @@ def interpolation_chunk(value_code = "#{local_name}")
end

def extract_value
"#{local_name} = hash[:#{key}] && hash[:#{key}].collect { |path_component| URI.escape(path_component, ActionController::Routing::Segment::UNSAFE_PCHAR) }.to_param #{"|| #{default.inspect}" if default}"
"#{local_name} = hash[:#{key}] && hash[:#{key}].collect { |path_component| URI.escape(path_component.to_param, ActionController::Routing::Segment::UNSAFE_PCHAR) }.to_param #{"|| #{default.inspect}" if default}"
end

def default
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -50,6 +50,13 @@ def test_route_recognition_unescapes_path_components
:additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"] }
assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2")
end

def test_route_generation_allows_passing_non_string_values_to_generated_helper
assert_equal "/controller/action/variable/1/2", @set.generate(:controller => "controller",
:action => "action",
:variable => "variable",
:additional => [1, 2])
end
end

class LegacyRouteSetTests < Test::Unit::TestCase
Expand Down

0 comments on commit 345f030

Please sign in to comment.