aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-21 00:40:51 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-21 00:40:51 +0000
commitb88fa4d1df7763245a14f9d81a4206273acd2d7e (patch)
treecd61654aaa861abef3d2faa8d162a29c4fccb5fd
parenteb73846f481fcba26708f2a1bc4df289ab74acfc (diff)
downloadrails-b88fa4d1df7763245a14f9d81a4206273acd2d7e.tar.gz
rails-b88fa4d1df7763245a14f9d81a4206273acd2d7e.tar.bz2
rails-b88fa4d1df7763245a14f9d81a4206273acd2d7e.zip
Routes: *path items should use arrays #883
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@954 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG4
-rw-r--r--actionpack/lib/action_controller/routing.rb14
-rw-r--r--actionpack/test/controller/routing_tests.rb14
3 files changed, 26 insertions, 6 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 90fef28e3e..dee0ce136d 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -55,7 +55,9 @@
map.connect 'categories/*path_info', :controller => 'categories', :action => 'show'
A request for /categories/top-level-cat, would give @params[:path_info] with "top-level-cat".
- A request for /categories/top-level-cat/level-1-cat, would give @params['path_info'] with "top-level-cat/level-1-cat" and so forth.
+ A request for /categories/top-level-cat/level-1-cat, would give @params[:path_info] with "top-level-cat/level-1-cat" and so forth.
+
+ The @params[:path_info] return is really an array, but where to_s has been overwritten to do join("/").
* Fixed options_for_select on selected line issue #624 [Florian Weber]
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index 0e97b7174f..0d4143fa87 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -47,6 +47,7 @@ module ActionController
used_names = @requirements.inject({}) {|hash, (k, v)| hash[k] = true; hash} # Mark requirements as used so they don't get put in the query params
components = @items.collect do |item|
+
if item.kind_of? Symbol
collection = false
@@ -64,7 +65,12 @@ module ActionController
if value.nil? || item == :controller
value
elsif collection
- Routing.extract_parameter_value(value).gsub(/%2F/, "/")
+ if value.kind_of?(Array)
+ value = value.collect {|v| Routing.extract_parameter_value(v)}.join('/')
+ else
+ value = Routing.extract_parameter_value(value).gsub(/%2F/, "/")
+ end
+ value
else
Routing.extract_parameter_value(value)
end
@@ -113,9 +119,11 @@ module ActionController
options[:controller] = controller_class.controller_path
return nil, requirements_for(:controller) unless passes_requirements?(:controller, options[:controller])
elsif /^\*/ =~ item.to_s
- value = components.join("/") || @defaults[item]
+ value = components.empty? ? @defaults[item].clone : components.clone
+ value.collect! {|c| CGI.unescape c}
components = []
- options[item.to_s.sub(/^\*/,"").intern] = value.nil? ? value : CGI.unescape(value)
+ def value.to_s() self.join('/') end
+ options[item.to_s.sub(/^\*/,"").intern] = value
elsif item.kind_of? Symbol
value = components.shift || @defaults[item]
return nil, requirements_for(item) unless passes_requirements?(item, value)
diff --git a/actionpack/test/controller/routing_tests.rb b/actionpack/test/controller/routing_tests.rb
index f36e395107..a5b6066d66 100644
--- a/actionpack/test/controller/routing_tests.rb
+++ b/actionpack/test/controller/routing_tests.rb
@@ -329,11 +329,21 @@ class RouteTests < Test::Unit::TestCase
def test_path_collection
route '*path_info', :controller => 'content', :action => 'fish'
verify_recognize'path/with/slashes',
- :controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'
+ :controller => 'content', :action => 'fish', :path_info => %w(path with slashes)
verify_generate('path/with/slashes', {},
- {:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'},
+ {:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'},
{})
end
+ def test_path_collection_with_array
+ route '*path_info', :controller => 'content', :action => 'fish'
+ verify_recognize'path/with/slashes',
+ :controller => 'content', :action => 'fish', :path_info => %w(path with slashes)
+ verify_generate('path/with/slashes', {},
+ {:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)},
+ {})
+ end
+
+
def test_special_characters
route ':id', :controller => 'content', :action => 'fish'