This project is archived and is in readonly mode.

#5999 ✓resolved
Caleb Land

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

Reported by Caleb Land | November 18th, 2010 @ 12:04 AM | in 3.0.6

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

Comments and changes to this ticket

  • Andrew White

    Andrew White November 18th, 2010 @ 06:45 AM

    • State changed from “new” to “open”
    • Milestone cleared.
    • Assigned user set to “Andrew White”
    • Importance changed from “” to “Low”
  • 2kan

    2kan November 24th, 2010 @ 05:35 PM

    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.

  • 2kan

    2kan November 24th, 2010 @ 05:37 PM

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

  • 2kan

    2kan November 25th, 2010 @ 12:26 PM

    @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?

  • Szymon Kurcab

    Szymon Kurcab December 7th, 2010 @ 10:00 AM

    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"

  • Szymon Kurcab

    Szymon Kurcab December 7th, 2010 @ 10:04 AM

    Running in Rails 3.0.1 console (JRuby 1.5.3)

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

    Yaroslav Markin December 29th, 2010 @ 04:38 PM

    • Tag changed from routing to actionpack, rack, routing

    Andrew, any feedback? :-/

  • Ravil Bayramgalin
  • Santiago Pastorino
  • Santiago Pastorino

    Santiago Pastorino February 27th, 2011 @ 03:15 AM

    • Milestone changed from 3.0.5 to 3.0.6
  • Andrew White

    Andrew White March 23rd, 2011 @ 05:50 PM

    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.

  • Andrew White

    Andrew White April 6th, 2011 @ 05:59 PM

    • State changed from “open” to “resolved”

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

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