This project is archived and is in readonly mode.
better error messages when incorrect regexp is passed to constraints in routes
-
Rohit Arondekar
- State changed from new to invalid
- Importance changed from to Low
According to the docs you can use normal regexp's with the start/end markes: http://guides.rubyonrails.org/routing.html#specifying-constraints
Am I missing something? Maybe this was fixed along the way. I'm closing the ticket, however if this is still an issue just leave a comment with steps to reproduce the problem, or a patch and I'll reopen.
-
Jakub Suder
Well, the guide you linked to shows examples with regexps without start/end markers...
Example from that link:
constraints(:id => /[A-Z][A-Z][0-9]+/) doAnd if you do this:
constraints(:id => /^[A-Z][A-Z][0-9]+$/) doyou get a confusing error and you waste half an hour trying to figure out what may be wrong (it's not just me, someone else from my team had this last week too). This happens on Rails 3.0.0 final, I'm not sure about latest development version.
-
Rohit Arondekar
- State changed from invalid to open
- Assigned user set to Andrew White
Sorry for that!
Well I think I've seen something similar. And iirc, it's not possible/easy to allow use of start/end markers in constraints.
Assigning to Andrew for clarification.
-
Andrew White
- Milestone cleared.
There's a commit on master which raises an ArgumentError when an anchor is used in a constraint:
http://github.com/rails/rails/commit/ca3936dbd691538d97d8dbe2bc1d64...It's impossible to add anchor support to routing constraints since each regexp is assembled into a larger regexp with it's own anchors. Validations are different because there you are specifying the whole regexp rather than just a fragment so it's perfectly valid that you might want to use an anchor.
I'll backport the above commit to the 3-0-stable branch - I believe something similar already exists in the 2-3-stable branch.
-
David Trasbo
- State changed from open to resolved
Fixed on
masterand will be backported to3-0-stable. -
Jakub Suder
That should be enough, thanks.