Should I be able to escape and use reserved URI characters within Rails routing?

I have two failing tests (below) that illustrate my expected behaviour. I’m just not sure that my expectations are correct.

In a nutshell. Should ‘/foo/bar%2Fbaz’ try to match [‘foo’, ‘bar’, ‘baz’] or [‘foo’, ‘bar%2Fbaz’].

Chris

class UriReservedCharactersRoutingTest < Test::Unit::TestCase

def setup ActionController::Routing.use_controllers! [‘controller’] @set = ActionController::Routing:: RouteSet.new @set.draw do |map| map.connect ‘:controller/:action/:var’ end end

def test_should_escape_reserved_uri_characters_within_individual_path_components assert_equal ‘/controller/action/p1%2Fp2’, @ set.generate(:controller => ‘controller’, :action => ‘action’, :var => ‘p1/p2’) end

def test_should_recognize_escaped_path_component_and_unescape expected_options = {:var => “p1/p2”, :controller => “controller”, :action => “action”}

assert_equal expected_options, @set.recognize_path('/controller/action/p1%2Fp2')

end

end

Ok, so I’ve kinda convinced myself that my expectations were correct, and that the current routing implementation wasn’t quite right.

I’ve extended the tests and provided a fix in the attached patch. Should I just go ahead and add as a ticket in trac?

Chris

routing.patch (4.99 KB)

Please do. I agree the behavior is wrong.

jeremy

Ok, all done.

http://dev.rubyonrails.org/ticket/7544

Chris

Does anyone else have any input here, or should I just turn it into a plugin?

Chris

Applied. Thanks Chris.

jeremy