Routes requirements exclude one character

Hi!

Consider the following route:
map.detail "subscription_plans/:provider/:plan", :action =>
"detail", :requirements => {:plan => /[^ ]+/}

I want this route to match any string _without_ a space character. So
"Telfort-100" matches "Telfort 100" does not.

I believed this to be correct but it's not. Including anchors ('\A'
'$' etc) is not allowed. How else can I fix this?

Harm

The regexp you've specified here will match as long as there are at
least two consecutive non-space characters. The only way I can think
of to do what you're looking for would be to add a route preceding
this one which matches any :plan WITH a space, and routes it to an
error page. EG:

map.bad_detail "subscription_plans/:provider/:plan", :action =>
'detail_error', :requirements => { :plan => /[ ]/ }
map.detail "subscription_plans/:provider/:plan", :action => 'detail'

--Matt Jones

Matt Jones wrote:

The regexp you've specified here will match as long as there are at
least two consecutive non-space characters.

I would have thought so, but the routing docs suggest that the regex is
implicitly anchored at both ends (look at the postalcode example).

The only way I can think
of to do what you're looking for would be to add a route preceding
this one which matches any :plan WITH a space, and routes it to an
error page.

That's clever!

Best,

That _is_ clever!

I still believe Rails is in error here. The docs indeed do suggest
that the stuff is anchored. Clearly it's not. I'll consider making a
ticket.

Thanks for the input guys!