This project is archived and is in readonly mode.

#2905 ✓stale
theirishpenguin

Named routes do not handle parameters with a "/" in the values

Reported by theirishpenguin | July 13th, 2009 @ 03:17 PM | in 3.x

Steps to reproduce

  • Create an application which has at least one named route named route

  • Start up ./script/console and type

app.my_named_route_url('cats/dogs')

... replacing my_named_route with the route name of your choice

Expected result

  • A route is successfully generated

Actual result

  • The following error

ActionController::RoutingError: user_url failed to generate from {:action=>"show", :controller=>"users", :id=>"cats/dogs"}, expected: {:controller=>"users", :action=>"show"}, diff: {:id=>"cats/dogs"}

from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:422:in `raise_named_route_error'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:386:in `generate'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:205:in `rewrite_path'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:184:in `rewrite_url'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:162:in `rewrite'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/integration.rb:243:in `url_for'
from (eval):16:in `user_url'
from (irb):7

Comments and changes to this ticket

  • anupom syam

    anupom syam July 14th, 2009 @ 07:36 PM

    It seems working fine for me.

    app.my_named_route_url('cats/dogs') => "http://www.example.com/help/cats%2Fdogs"

    I found appropriate unit tests for this (see test_paths_escaped()) in routing_testrb as well.

    Which version are you using?

  • Carl Lerche

    Carl Lerche July 15th, 2009 @ 09:42 PM

    • State changed from “new” to “invalid”

    I tried reproducing this as well and it seems to work for me. I am going to mark this ticket as invalid, but feel free to reopen it if you have more information.

  • theirishpenguin

    theirishpenguin July 16th, 2009 @ 10:49 PM

    Thanks for your quick reply folks. I am using version Rails 2.3.2.

    I have tried this on a different machine and, like ye, it now works for me. This is very strange as I'd tried this already on a couple of machines. Mustn't be anything to do with Rails though.

    Thanks for your quick reply. Much appreciated,
    Declan

  • theirishpenguin

    theirishpenguin July 17th, 2009 @ 11:26 AM

    I have successfully reproduced the bug - It is unfortunate that my original test case was a little vague. Here are the exact steps to reproduce

    • Create a new rails app via 'rails farmhouse'
    • Inside the app, run './script/generate scaffold pig'
    • Do a './script/console'

      ./script/generate scaffold pig => Loading development environment (Rails 2.3.2)

      app.pigs_url('cat/dog') => "http://www.example.com/pigs.cat%2Fdog"

      app.pig_url('catdog') => "http://www.example.com/pigs/catdog"

      app.pig_url('cat/dog') ActionController::RoutingError: pig_url failed to generate from {:controller=>"pigs", :id=>"cat/dog", :action=>"show"}, expected: {:controller=>"pigs", :action=>"show"}, diff: {:id=>"cat/dog"}
      from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:422:in raise_named_route_error' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:386:ingenerate' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:205:in rewrite_path' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:184:inrewrite_url' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:162:in rewrite' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/integration.rb:243:inurl_for' from (eval):16:in pig_url' from (irb):1

    • If I then run rake routes, I get the following route pig GET /pigs/:id(.:format) {:action=>"show", :controller=>"pigs"}

    • So, irrespective of having a forward slash in the value or not, I should get a valid route back for my piggy :-)

    I will attempt to reproduce it on another test machine later. If that is successful I will reopen the bug. I don't want to waste your time in the event that it is an environment problem on my end. Just to reiterate I am using Rails 2.3.2. Thanks again.

  • theirishpenguin

    theirishpenguin July 24th, 2009 @ 02:28 PM

    Just quick update. I've tested this this against Rails 2.3.3 and I am still getting the same behaviour.

  • Michael Koziarski

    Michael Koziarski August 3rd, 2009 @ 06:16 AM

    • Assigned user set to “Carl Lerche”
    • State changed from “invalid” to “open”

    reopening

  • PreciousBodilyFluids

    PreciousBodilyFluids December 22nd, 2009 @ 02:14 AM

    Still present on Rails 2.3.5, and rather annoying.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Indrek Juhkam

    Indrek Juhkam June 5th, 2010 @ 09:08 PM

    seems to work in rails 3

  • Ken Robertson

    Ken Robertson July 21st, 2010 @ 06:25 PM

    I've been experiencing this on Rails3 beta4. I'm working on porting an app from Merb to Rails3, so no experience with whether this is an issue in Rails 2.3.

    I also created a bare Rails3 beta4 app and reproduced it with a very simple setup. I created a route like so:

    match '/blah/:id' => 'home#blah', :as => :someroute, :constraints => { :id => /[A-Za-z0-9\/]*/ }

    Then in my template, simply had:

    someroute_path('one/two')

    And it throws the error:

    ActionController::RoutingError in Home#index No route matches {:controller=>"home", :action=>"blah", :id=>"one/two"}

    I dug down about as far as I could go. The issue seems to actually be in rack-mount. On startup of the app, rack-mount composes all the routes and translates the route into named segments. It is during that where the regex for the constraint is being altered to drop the slash.

    I've traced it down to Rack::Mount::Utils.parse_regexp, when it calls Regin.parse(regexp). Before that, the regexp is fine, after that, when it converts it into an Expression, it is missing the slash. It seems to use Regin::Parser to parse it and segment it, but haven't had a change to debug it enough to find the cause.

  • Brian Rose
  • Ken Robertson

    Ken Robertson July 21st, 2010 @ 10:52 PM

    Yes, it does. Somehow I got lead down the wrong path this morning. Must have been lack of sleep.

    It was related to the value being escaped. I found I could get around it by using someroute_path(['one','two']). I think splitting the string would be good. I don't know if there are cases when it'd need more than just a slash.

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer November 8th, 2010 @ 08:52 AM

    • Tag cleared.
    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

  • Santiago Pastorino

    Santiago Pastorino February 9th, 2011 @ 12:31 AM

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 9th, 2011 @ 12:31 AM

    • State changed from “open” to “stale”
  • bingbing

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