This project is archived and is in readonly mode.
better error messages when incorrect regexp is passed to constraints in routes
Reported by Jakub Suder | August 2nd, 2010 @ 05:06 PM | in 3.0.2
The :constraints parameter in routes expects a regexp without
the start/end markers (which is the opposite to e.g. the regexps
passed to validation methods in ActiveModel). If you pass a full
regexp like /^\w+$/, you get a strange exception message "undefined
method include?' for #<Anchor "^">" coming from
rack-mount.
It would be more consistent if the regexp style was the same in routes and in ActiveModel, but if that's not possible, then maybe Rails could print more meaningful error messages when incorrect regexp is passed to :constraints instead of that exception.
Comments and changes to this ticket
-
Rohit Arondekar October 7th, 2010 @ 06:38 AM
- 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 October 7th, 2010 @ 07:51 PM
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]+/) do
And if you do this:
constraints(:id => /^[A-Z][A-Z][0-9]+$/) do
you 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 October 8th, 2010 @ 02:07 AM
- 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 October 8th, 2010 @ 07:02 AM
- 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 October 8th, 2010 @ 08:41 AM
- State changed from open to resolved
Fixed on
master
and will be backported to3-0-stable
. -
Repository October 8th, 2010 @ 11:21 AM
(from [981942a326d5cc3b7ae0639d1d8c793ae8010a74]) Backport ca3936d to 3-0-stable [#5274] http://github.com/rails/rails/commit/981942a326d5cc3b7ae0639d1d8c79...
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>
People watching this ticket
Tags
Referenced by
- 5274 better error messages when incorrect regexp is passed to constraints in routes (from [981942a326d5cc3b7ae0639d1d8c793ae8010a74]) Backpor...