Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #883: route_paths_as_arrays.patch

File route_paths_as_arrays.patch, 2.8 kB (added by Ulysses, 4 years ago)

Patch as discussed above

  • actionpack/lib/action_controller/routing.rb

    old new  
    4747         
    4848        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 
    4949        components = @items.collect do |item| 
     50 
    5051          if item.kind_of? Symbol 
    5152            collection = false 
    5253 
     
    6970              else 
    7071                value = Routing.extract_parameter_value(value).gsub(/%2F/, "/") 
    7172              end 
     73              value 
    7274            else 
    7375              Routing.extract_parameter_value(value) 
    7476            end 
     
    117119            options[:controller] = controller_class.controller_path 
    118120            return nil, requirements_for(:controller) unless passes_requirements?(:controller, options[:controller]) 
    119121          elsif /^\*/ =~ item.to_s 
    120             value = components.empty? @defaults[item].clone : components.clone 
     122            value = components.empty? ? @defaults[item].clone : components.clone 
    121123            value.collect! {|c| CGI.unescape c} 
    122124            components = [] 
    123             def value.to_s() self.join('/') 
     125            def value.to_s() self.join('/') end 
    124126            options[item.to_s.sub(/^\*/,"").intern] = value 
    125127          elsif item.kind_of? Symbol 
    126128            value = components.shift || @defaults[item] 
  • actionpack/test/controller/routing_tests.rb

    old new  
    329329  def test_path_collection 
    330330    route '*path_info', :controller => 'content', :action => 'fish' 
    331331    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) 
    333333    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'}, 
    335335        {}) 
    336336  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 
    337347   
    338348  def test_special_characters 
    339349    route ':id', :controller => 'content', :action => 'fish'