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.

Route constraints regex with predefined characters classes in square brackets does not work

#5999

I am getting a "No route matches" error when I try to generate a url for this route:

match 'posts/:token', :to => 'posts#show', :constraints => { :token => /[\d]+/ }, :as => 'token_post'

with this helper:

token_post_path('102')

If I remove the square brackets from the :constraints entry for :token (making the regex /\d+/), everything works fine.

It also works if I replace \d in the regex with 0-9

I am running ruby 1.9.2-p0 on rails 3.0.3

Reported by Caleb Land · November 18th, 2010 @ 12:04 AM

State: resolved
Milestone: 3.0.6
Assigned to: Andrew White Andrew White
Importance: Low

Activity

  1. Andrew White
    Andrew White
    • State changed from new to open
    • Milestone cleared.
    • Assigned user set to Andrew White
    • Importance changed from to Low

    November 18th, 2010 @ 06:45 AM

  2. 2kan
    2kan

    Looks like there is a bug in grammar for Regin regexp parser, because after we parse a regexp to expressions the "" symbol before "d" in regexp is lost. Gonna work on it tonight.

    November 24th, 2010 @ 05:35 PM

  3. 2kan
    2kan

    Oops. The \ symbol is lost. So [\d]+ becomes [d]+.

    November 24th, 2010 @ 05:37 PM

  4. 2kan
    2kan

    @Andrew White I think there is a bug in

    expression = Regin.parse(regexp)
    

    in Rack::Mount::Utits.parse_regexp

    And i see generated files in rack/mouint/vendor/regin/regin but there is no grammar files, also in the beginning of the files:

    #
    # DO NOT MODIFY!!!!
    # This file is automatically generated by Racc 1.4.6
    # from Racc grammer file "".
    #
    

    So where can i get grammar files to find and fix a bug?

    November 25th, 2010 @ 12:26 PM

  5. Szymon Kurcab
    Szymon Kurcab

    It seems to me that this is a HIGH priority issue.
    The problem is with rack-mount using reign (as mentioned before) in Rails Router.

    Running in Rails 3.0.1 console (JRuby 1.5.3)

    jruby-1.5.3 > expression = Regin.parse(/\D[%-.\w]*/)
    => #

    router.rb with the route definition

    NCNAME = /\D[%-.\w]*/

    match "/items/:item_id", :to => "items#index", :as => "item_base", :constraints => { :service_id => NCNAME }

    Rails console tests:

    jruby-1.5.3 > item_base_path('f')
    => "/items/f" jruby-1.5.3 > item_base_path('fee')
    ActionController::RoutingError: No route matches {:controller=>"items", :item_id=>"fee"}

    jruby-1.5.3 > item_base_path('f.......')
    => "/items/f......." jruby-1.5.3 > item_base_path('fwwww')
    => "/items/fwwww" jruby-1.5.3 > item_base_path('fww-----....%ww')
    => "/items/fww-----....%ww"

    December 7th, 2010 @ 10:00 AM

  6. Szymon Kurcab
    Szymon Kurcab

    Running in Rails 3.0.1 console (JRuby 1.5.3)

    jruby-1.5.3 > expression = Regin.parse(/\D[%-\.\w]*/) 
     => #<Expression "\\D[%-.w]*">
    

    December 7th, 2010 @ 10:04 AM

  7. Yaroslav Markin
    Yaroslav Markin
    • Tag changed from routing to actionpack, rack, routing

    Andrew, any feedback? :-/

    December 29th, 2010 @ 04:38 PM

  8. Ravil Bayramgalin
  9. Santiago Pastorino
  10. Santiago Pastorino
    Santiago Pastorino
    • Milestone changed from 3.0.5 to 3.0.6

    February 27th, 2011 @ 03:15 AM

  11. Andrew White
    Andrew White

    Okay, sent a pull request to Josh. Once that's been applied and then the vendored regin in rack-mount is updated we can then look at bumping the rack-mount version.

    March 23rd, 2011 @ 05:50 PM

  12. Andrew White
    Andrew White
    • State changed from open to resolved

    This is now fixed in Rack::Mount 0.6.14 / Rails 3.0.6.

    April 6th, 2011 @ 05:59 PM