This project is archived and is in readonly mode.

#3612 ✓wontfix
mjf

Encoded slash is not unencoded in a functional test.

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

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"}

Comments and changes to this ticket

  • mjf

    mjf December 24th, 2009 @ 09:20 AM

    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).

  • Prem Sichanugrist (sikachu)

    Prem Sichanugrist (sikachu) October 17th, 2010 @ 05:34 PM

    • 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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages