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

Changeset 7487

Show
Ignore:
Timestamp:
09/15/07 22:10:20 (1 year ago)
Author:
bitsweat
Message:

Fixed optimized route segment escaping. Closes #9562.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r7482 r7487  
    11*SVN* 
     2 
     3* Fixed optimized route segment escaping.  #9562 [wildchild, Jeremy Kemper] 
    24 
    35* root_path returns '/' not ''.  #9563 [lifofifo] 
  • trunk/actionpack/lib/action_controller/routing_optimisation.rb

    r7482 r7487  
    5757          idx = 0 
    5858 
    59  
    6059          if kind == :url 
    6160            elements << '#{request.protocol}' 
     
    6867          ((route.segments.size == 1 && kind == :path) ? route.segments : route.segments[0..-2]).each do |segment| 
    6968            if segment.is_a?(DynamicSegment) 
    70               elements << "\#{URI.escape(args[#{idx}].to_param, ActionController::Routing::Segment::UNSAFE_PCHAR)}" 
     69              elements << segment.interpolation_chunk("args[#{idx}].to_param") 
    7170              idx += 1 
    7271            else 
    73               elements << segment.to_s 
     72              elements << segment.interpolation_chunk 
    7473            end 
    7574          end 
  • trunk/actionpack/lib/action_controller/routing.rb

    r7438 r7487  
    719719      end 
    720720   
    721       def interpolation_chunk 
    722         "\#{URI.escape(#{local_name}.to_s, ActionController::Routing::Segment::UNSAFE_PCHAR)}" 
     721      def interpolation_chunk(value_code = "#{local_name}.to_s") 
     722        "\#{URI.escape(#{value_code}, ActionController::Routing::Segment::UNSAFE_PCHAR)}" 
    723723      end 
    724724   
     
    777777 
    778778      # Don't URI.escape the controller name since it may contain slashes. 
    779       def interpolation_chunk 
    780         "\#{#{local_name}.to_s}" 
     779      def interpolation_chunk(value_code = "#{local_name}.to_s") 
     780        "\#{#{value_code}}" 
    781781      end 
    782782 
     
    800800      UNSAFE_PCHAR = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze 
    801801 
    802       def interpolation_chunk 
    803         "\#{URI.escape(#{local_name}.to_s, ActionController::Routing::PathSegment::UNSAFE_PCHAR)}" 
     802      def interpolation_chunk(value_code = "#{local_name}.to_s") 
     803        "\#{URI.escape(#{value_code}, ActionController::Routing::PathSegment::UNSAFE_PCHAR)}" 
    804804      end 
    805805 
     
    11511151            helpers << selector 
    11521152          end 
    1153            
     1153 
    11541154          def define_url_helper(route, name, kind, options) 
    11551155            selector = url_helper_name(name, kind) 
    11561156            # The segment keys used for positional paramters 
    1157              
     1157 
    11581158            hash_access_method = hash_access_name(name, kind) 
    1159              
     1159 
     1160            # allow ordered parameters to be associated with corresponding 
     1161            # dynamic segments, so you can do 
     1162            # 
     1163            #   foo_url(bar, baz, bang) 
     1164            # 
     1165            # instead of 
     1166            # 
     1167            #   foo_url(:bar => bar, :baz => baz, :bang => bang) 
     1168            # 
     1169            # Also allow options hash, so you can do 
     1170            # 
     1171            #   foo_url(bar, baz, bang, :sort_by => 'baz') 
     1172            # 
    11601173            @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks 
    11611174              def #{selector}(*args) 
    1162  
    11631175                #{generate_optimisation_block(route, kind)} 
    1164                  
     1176 
    11651177                opts = if args.empty? || Hash === args.first 
    11661178                  args.first || {} 
    11671179                else 
    1168                   # allow ordered parameters to be associated with corresponding 
    1169                   # dynamic segments, so you can do 
    1170                   # 
    1171                   #   foo_url(bar, baz, bang) 
    1172                   # 
    1173                   # instead of 
    1174                   # 
    1175                   #   foo_url(:bar => bar, :baz => baz, :bang => bang) 
    1176                   # 
    1177                   # Also allow options hash, so you can do 
    1178                   # 
    1179                   #   foo_url(bar, baz, bang, :sort_by => 'baz') 
    1180                   # 
    11811180                  options = args.last.is_a?(Hash) ? args.pop : {} 
    11821181                  args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)| 
     
    11861185                  options.merge(args) 
    11871186                end 
    1188                  
     1187 
    11891188                url_for(#{hash_access_method}(opts)) 
    11901189              end 
     
    11941193          end 
    11951194      end 
    1196    
     1195 
    11971196      attr_accessor :routes, :named_routes 
    11981197   
  • trunk/actionpack/test/controller/routing_test.rb

    r7482 r7487  
    274274  end 
    275275   
     276  def test_paths_slashes_unescaped_with_ordered_parameters 
     277    rs.add_named_route :path, '/file/*path', :controller => 'content'  
     278 
     279    # No / to %2F in URI, only for query params.  
     280    x = setup_for_named_route  
     281    assert_equal("/file/hello/world", x.send(:path_path, 'hello/world')) 
     282  end 
     283   
    276284  def test_non_controllers_cannot_be_matched 
    277285    rs.draw do |map|