Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Encoded slash is not unencoded in a functional test.

#3612

I am using Rails 2.3.2, Ruby 1.8.7, and Passenger 2.2.5.

I have a route like this where a parameter cannot contain an unencoded slash:

map.connect 'foo/:id', :controller => 'foo', :id => /[^\/]*/

If I access that path with an encoded slash:

$ curl http://example.com/foo/hi%2Fbye

then FooController handles it with params["id"] = "hi/bye" (literal slash)

But I cannot test this in a functional test:

class FooControllerTest < ActionController::TestCase
  def test_foo_escaped
    get :index, :id => "hi%2Fbye"
  end

  def test_foo_unescaped
    get :index, :id => "hi/bye"
  end
end

test_foo_escaped results in FooController invoked with params["id"] = "hi%2Fbye" (encoded slash)

test_foo_unescaped results in a RoutingError:

ActionController::RoutingError: No route matches {:action=>"index", :controller=>"foo", :id=>"hi/bye"}

Reported by mjf · December 24th, 2009 @ 07:18 AM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. mjf
    mjf

    My current workaround is to use an integration test rather than a functional test so the URL can be specified directly. But some special handing for the escaping is still required.

    def test_foo

    id = "hi/bye"
    url = url_for({ :controller => 'foo', :id => CGI.escape(id)})
    url = CGI.unescape(url)
    get url
    

    end

    This results in FooController being invoked with params["id"] = "hi/bye" (literal slash).

    December 24th, 2009 @ 09:20 AM

  2. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)
    • State changed from new to wontfix
    • Importance changed from to Low

    Hi,

    I can confirm that the example you provided still returning a fail test case on Rails 3.0.1. However, I think if you navigate to http://some.domain/foo/hi/bye Rails would route it to foo/hi#bye. There's no way the hi/bye will be parsed as an :id.

    So, I think I would mark this ticket as wontfix, and I agree that you should always escape your parameters in the test suit, make it like a real URL request.

    October 17th, 2010 @ 05:34 PM