Route constraints match empty strings in 3.2 ? #4136

Closed
jdelStrother opened this Issue Dec 22, 2011 · 5 comments

Projects

None yet

4 participants

Contributor

Hi,
I have the following route :

get ':username'=>'users#show', :username=>/[^\/]+/

for 'twitter style' profile urls, routing http://localhost:3000/foo to {:controller=>'users', :action=>'show', :username=>'foo'}

Under 3.2, this constraint now seems to match an empty string : if I visit http://localhost:3000/, it calls the users#show action with {"username"=>""} as a parameter.

Am I doing something wrong, or does it need further investigation?

Contributor

Your root route should be above the get ':username'=>'users#show', :username=>/[^\/]+/ so it won't go any further.

I realize it is not directly related to your issue, but your user-catching route should be at the end of routes.rb anyway.

Contributor

Mm, fair enough. Just thought it was weird that /[^\/]+/ seemed to be matching an empty string

Contributor

I know we cant use the dash symbol but maybe $ at the end will prevent matching?

Owner

@tenderlove this is a definite regression from 3.1 -> 3.2, I'll see if I can track down where the problem is.

The problem only occurs if there's a constraint - leaving out the regexp works as expected.

Owner

Ya, the generated regex seems to mark that as optional. I'll also take a look when I get home.

Aaron Patterson
http://tenderlovemaking.com/

On Dec 22, 2011, at 1:43 PM, Andrew Whitereply@reply.github.com wrote:

@tenderlove this is a definite regression from 3.1 -> 3.2, I'll see if I can track down where the problem is.

The problem only occurs if there's a constraint - leaving out the regexp works as expected.


Reply to this email directly or view it on GitHub:
#4136 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment