Browse files

Routes: *path items should use arrays #883

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@954 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent eb73846 commit b88fa4d1df7763245a14f9d81a4206273acd2d7e @dhh dhh committed Mar 21, 2005
Showing with 26 additions and 6 deletions.
  1. +3 −1 actionpack/CHANGELOG
  2. +11 −3 actionpack/lib/action_controller/routing.rb
  3. +12 −2 actionpack/test/controller/routing_tests.rb
View
4 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]
View
14 actionpack/lib/action_controller/routing.rb
@@ -47,6 +47,7 @@ def generate(options, defaults={})
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 @@ def generate(options, defaults={})
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 @@ def recognize(components, options={})
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)
View
14 actionpack/test/controller/routing_tests.rb
@@ -329,11 +329,21 @@ def test_expand_controller_path_nested_no_leftover
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'

0 comments on commit b88fa4d

Please sign in to comment.