Changeset 7487
- Timestamp:
- 09/15/07 22:10:20 (1 year ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/routing_optimisation.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/routing.rb (modified) (6 diffs)
- trunk/actionpack/test/controller/routing_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r7482 r7487 1 1 *SVN* 2 3 * Fixed optimized route segment escaping. #9562 [wildchild, Jeremy Kemper] 2 4 3 5 * root_path returns '/' not ''. #9563 [lifofifo] trunk/actionpack/lib/action_controller/routing_optimisation.rb
r7482 r7487 57 57 idx = 0 58 58 59 60 59 if kind == :url 61 60 elements << '#{request.protocol}' … … 68 67 ((route.segments.size == 1 && kind == :path) ? route.segments : route.segments[0..-2]).each do |segment| 69 68 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") 71 70 idx += 1 72 71 else 73 elements << segment. to_s72 elements << segment.interpolation_chunk 74 73 end 75 74 end trunk/actionpack/lib/action_controller/routing.rb
r7438 r7487 719 719 end 720 720 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)}" 723 723 end 724 724 … … 777 777 778 778 # 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}}" 781 781 end 782 782 … … 800 800 UNSAFE_PCHAR = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze 801 801 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)}" 804 804 end 805 805 … … 1151 1151 helpers << selector 1152 1152 end 1153 1153 1154 1154 def define_url_helper(route, name, kind, options) 1155 1155 selector = url_helper_name(name, kind) 1156 1156 # The segment keys used for positional paramters 1157 1157 1158 1158 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 # 1160 1173 @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks 1161 1174 def #{selector}(*args) 1162 1163 1175 #{generate_optimisation_block(route, kind)} 1164 1176 1165 1177 opts = if args.empty? || Hash === args.first 1166 1178 args.first || {} 1167 1179 else 1168 # allow ordered parameters to be associated with corresponding1169 # dynamic segments, so you can do1170 #1171 # foo_url(bar, baz, bang)1172 #1173 # instead of1174 #1175 # foo_url(:bar => bar, :baz => baz, :bang => bang)1176 #1177 # Also allow options hash, so you can do1178 #1179 # foo_url(bar, baz, bang, :sort_by => 'baz')1180 #1181 1180 options = args.last.is_a?(Hash) ? args.pop : {} 1182 1181 args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)| … … 1186 1185 options.merge(args) 1187 1186 end 1188 1187 1189 1188 url_for(#{hash_access_method}(opts)) 1190 1189 end … … 1194 1193 end 1195 1194 end 1196 1195 1197 1196 attr_accessor :routes, :named_routes 1198 1197 trunk/actionpack/test/controller/routing_test.rb
r7482 r7487 274 274 end 275 275 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 276 284 def test_non_controllers_cannot_be_matched 277 285 rs.draw do |map|