Ticket #883: route_paths_as_arrays.3.patch
| File route_paths_as_arrays.3.patch, 3.4 kB (added by Ulysses, 4 years ago) |
|---|
-
actionpack/test/controller/routing_tests.rb
old new 329 329 def test_path_collection 330 330 route '*path_info', :controller => 'content', :action => 'fish' 331 331 verify_recognize'path/with/slashes', 332 :controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'332 :controller => 'content', :action => 'fish', :path_info => %w(path with slashes) 333 333 verify_generate('path/with/slashes', {}, 334 {:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'},334 {:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'}, 335 335 {}) 336 336 end 337 def test_path_collection_with_array 338 route '*path_info', :controller => 'content', :action => 'fish' 339 verify_recognize'path/with/slashes', 340 :controller => 'content', :action => 'fish', :path_info => %w(path with slashes) 341 verify_generate('path/with/slashes', {}, 342 {:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)}, 343 {}) 344 end 345 346 337 347 338 348 def test_special_characters 339 349 route ':id', :controller => 'content', :action => 'fish' -
actionpack/lib/action_controller/routing.rb
old new 47 47 48 48 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 49 49 components = @items.collect do |item| 50 50 51 if item.kind_of? Symbol 51 52 collection = false 52 53 … … 64 65 if value.nil? || item == :controller 65 66 value 66 67 elsif collection 67 Routing.extract_parameter_value(value).gsub(/%2F/, "/") 68 if value.kind_of?(Array) 69 value = value.collect {|v| Routing.extract_parameter_value(v)}.join('/') 70 else 71 value = Routing.extract_parameter_value(value).gsub(/%2F/, "/") 72 end 73 value 68 74 else 69 75 Routing.extract_parameter_value(value) 70 76 end … … 113 119 options[:controller] = controller_class.controller_path 114 120 return nil, requirements_for(:controller) unless passes_requirements?(:controller, options[:controller]) 115 121 elsif /^\*/ =~ item.to_s 116 value = components.join("/") || @defaults[item] 122 value = components.empty? ? @defaults[item].clone : components.clone 123 value.collect! {|c| CGI.unescape c} 117 124 components = [] 118 options[item.to_s.sub(/^\*/,"").intern] = value.nil? ? value : CGI.unescape(value) 125 def value.to_s() self.join('/') end 126 options[item.to_s.sub(/^\*/,"").intern] = value 119 127 elsif item.kind_of? Symbol 120 128 value = components.shift || @defaults[item] 121 129 return nil, requirements_for(item) unless passes_requirements?(item, value)