public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Escape globbed parameters in routes correctly.

:controller => 'glob', :action=> 'show', :additional => 
['foo/bar', 'baz']

Should generate /glob/show/foo%2Fbar/baz not  /glob/show/foo/bar/baz
Chris Roos (author)
Fri May 09 19:55:11 -0700 2008
NZKoz (committer)
Fri May 09 19:55:41 -0700 2008
commit  6776edccf6fb553eb0ac6db55e1d30df1b5b6589
tree    0a3f2c239d1e316db4ab2d9b7532b0da679365aa
parent  dc4eec1129520ce9863c9373d7cb79d8636ab7ca
...
244
245
246
247
248
249
250
251
 
 
 
 
 
252
253
254
...
244
245
246
 
 
 
247
 
248
249
250
251
252
253
254
255
0
@@ -244,11 +244,12 @@
0
     end
0
 
0
     class PathSegment < DynamicSegment #:nodoc:
0
- RESERVED_PCHAR = "#{Segment::RESERVED_PCHAR}/"
0
- UNSAFE_PCHAR = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}#{RESERVED_PCHAR}]", false, 'N').freeze
0
-
0
       def interpolation_chunk(value_code = "#{local_name}")
0
- "\#{URI.escape(#{value_code}.to_s, ActionController::Routing::PathSegment::UNSAFE_PCHAR)}"
0
+ "\#{#{value_code}}"
0
+ end
0
+
0
+ def extract_value
0
+ "#{local_name} = hash[:#{key}] && hash[:#{key}].collect { |path_component| URI.escape(path_component, ActionController::Routing::Segment::UNSAFE_PCHAR) }.to_param #{"|| #{default.inspect}" if default}"
0
       end
0
 
0
       def default
...
25
26
27
28
 
29
30
31
32
33
...
36
37
38
39
 
40
41
42
 
 
43
44
45
46
47
48
49
 
 
 
50
51
52
...
25
26
27
 
28
29
30
31
32
33
...
36
37
38
 
39
40
41
 
42
43
44
45
46
47
48
 
 
49
50
51
52
53
54
0
@@ -25,7 +25,7 @@
0
     ActionController::Routing.use_controllers! ['controller']
0
     @set = ActionController::Routing::RouteSet.new
0
     @set.draw do |map|
0
- map.connect ':controller/:action/:variable'
0
+ map.connect ':controller/:action/:variable/*additional'
0
     end
0
 
0
     safe, unsafe = %w(: @ & = + $ , ;), %w(^ / ? # [ ])
0
0
0
@@ -36,17 +36,19 @@
0
   end
0
 
0
   def test_route_generation_escapes_unsafe_path_characters
0
- assert_equal "/contr#{@segment}oller/act#{@escaped}ion/var#{@escaped}iable",
0
+ assert_equal "/contr#{@segment}oller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2",
0
       @set.generate(:controller => "contr#{@segment}oller",
0
                     :action => "act#{@segment}ion",
0
- :variable => "var#{@segment}iable")
0
+ :variable => "var#{@segment}iable",
0
+ :additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"])
0
   end
0
 
0
   def test_route_recognition_unescapes_path_components
0
     options = { :controller => "controller",
0
                 :action => "act#{@segment}ion",
0
- :variable => "var#{@segment}iable" }
0
- assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable")
0
+ :variable => "var#{@segment}iable",
0
+ :additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"] }
0
+ assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2")
0
   end
0
 end
0
 

Comments

  • railsmonk Thu May 15 11:49:20 -0700 2008

    Now if I pass url_for(:something => my_obj), my_obj is not called to_param, so I get undefined method .collect error. Is that intentional?