aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-18 23:52:28 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-18 23:52:28 +0000
commit519fe7ccbc5798aa957e9a8ea146bb825cd79b9e (patch)
tree2d32e9e84eece6ec19053cb41771366833fb27be /actionpack
parent7a67d0f617db7d2962b6c3b80466e21570b244bf (diff)
downloadrails-519fe7ccbc5798aa957e9a8ea146bb825cd79b9e.tar.gz
rails-519fe7ccbc5798aa957e9a8ea146bb825cd79b9e.tar.bz2
rails-519fe7ccbc5798aa957e9a8ea146bb825cd79b9e.zip
Added URL escaping for routing #664
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@670 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/routing.rb6
-rw-r--r--actionpack/test/controller/routing_tests.rb12
2 files changed, 15 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index f08e23b72e..1f4d56ec01 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -41,7 +41,7 @@ module ActionController
value = options[item] || defaults[item] || @defaults[item]
return nil, "#{item.inspect} was not given and has no default." if value.nil? && ! (@defaults.key?(item) && @defaults[item].nil?) # Don't leave if nil value.
defaults = {} unless defaults == {} || value == defaults[item] # Stop using defaults if this component isn't the same as the default.
- value
+ (value.nil? || item == :controller) ? value : CGI.escape(value.to_s)
else item
end
end
@@ -89,7 +89,7 @@ module ActionController
elsif item.kind_of? Symbol
value = components.shift || @defaults[item]
return nil, "No value or default for parameter #{item.inspect}" if value.nil? && ! (@defaults.key?(item) && @defaults[item].nil?)
- options[item] = value
+ options[item] = value.nil? ? value : CGI.unescape(value)
else
return nil, "No value available for component #{item.inspect}" if components.empty?
component = components.shift
@@ -208,7 +208,7 @@ module ActionController
if controller.nil?
failures << [route, options] if ActionController::Base.debug_routes
else
- options.each {|k, v| request.path_parameters[k] = CGI.unescape(v)}
+ request.path_parameters = options
return controller
end
end
diff --git a/actionpack/test/controller/routing_tests.rb b/actionpack/test/controller/routing_tests.rb
index 821e66af70..69632c694f 100644
--- a/actionpack/test/controller/routing_tests.rb
+++ b/actionpack/test/controller/routing_tests.rb
@@ -278,6 +278,18 @@ class RouteTests < Test::Unit::TestCase
assert_equal Controllers::Admin::UserController, controller
assert_equal %w{action id}, leftovers
end
+
+ def test_special_characters
+ route ':id', :controller => 'content', :action => 'fish'
+ verify_recognize'id+with+spaces',
+ :controller => 'content', :action => 'fish', :id => 'id with spaces'
+ verify_generate('id+with+spaces', {},
+ {:controller => 'content', :action => 'fish', :id => 'id with spaces'}, {})
+ verify_recognize 'id%2Fwith%2Fslashes',
+ :controller => 'content', :action => 'fish', :id => 'id/with/slashes'
+ verify_generate('id%2Fwith%2Fslashes', {},
+ {:controller => 'content', :action => 'fish', :id => 'id/with/slashes'}, {})
+ end
end
class RouteSetTests < Test::Unit::TestCase