diff options
author | Chris Roos <chrisjroos@gmail.com> | 2008-05-10 14:55:11 +1200 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-05-10 14:55:41 +1200 |
commit | 6776edccf6fb553eb0ac6db55e1d30df1b5b6589 (patch) | |
tree | 0a3f2c239d1e316db4ab2d9b7532b0da679365aa | |
parent | dc4eec1129520ce9863c9373d7cb79d8636ab7ca (diff) | |
download | rails-6776edccf6fb553eb0ac6db55e1d30df1b5b6589.tar.gz rails-6776edccf6fb553eb0ac6db55e1d30df1b5b6589.tar.bz2 rails-6776edccf6fb553eb0ac6db55e1d30df1b5b6589.zip |
Escape globbed parameters in routes correctly.
:controller => 'glob', :action=> 'show', :additional => ['foo/bar', 'baz']
Should generate /glob/show/foo%2Fbar/baz not /glob/show/foo/bar/baz
-rw-r--r-- | actionpack/lib/action_controller/routing/segments.rb | 9 | ||||
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 12 |
2 files changed, 12 insertions, 9 deletions
diff --git a/actionpack/lib/action_controller/routing/segments.rb b/actionpack/lib/action_controller/routing/segments.rb index 24ea8c7f2d..b142d18b47 100644 --- a/actionpack/lib/action_controller/routing/segments.rb +++ b/actionpack/lib/action_controller/routing/segments.rb @@ -244,11 +244,12 @@ module ActionController end class PathSegment < DynamicSegment #:nodoc: - RESERVED_PCHAR = "#{Segment::RESERVED_PCHAR}/" - UNSAFE_PCHAR = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze - def interpolation_chunk(value_code = "#{local_name}") - "\#{URI.escape(#{value_code}.to_s, ActionController::Routing::PathSegment::UNSAFE_PCHAR)}" + "\#{#{value_code}}" + 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}" end def default diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 640afd58f8..b28f7bcdff 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -25,7 +25,7 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase ActionController::Routing.use_controllers! ['controller'] @set = ActionController::Routing::RouteSet.new @set.draw do |map| - map.connect ':controller/:action/:variable' + map.connect ':controller/:action/:variable/*additional' end safe, unsafe = %w(: @ & = + $ , ;), %w(^ / ? # [ ]) @@ -36,17 +36,19 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase end def test_route_generation_escapes_unsafe_path_characters - assert_equal "/contr#{@segment}oller/act#{@escaped}ion/var#{@escaped}iable", + assert_equal "/contr#{@segment}oller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2", @set.generate(:controller => "contr#{@segment}oller", :action => "act#{@segment}ion", - :variable => "var#{@segment}iable") + :variable => "var#{@segment}iable", + :additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"]) end def test_route_recognition_unescapes_path_components options = { :controller => "controller", :action => "act#{@segment}ion", - :variable => "var#{@segment}iable" } - assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable") + :variable => "var#{@segment}iable", + :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 end |