Unable to combine named regexes with trailing wildcards #6

Closed
yellincmp opened this Issue Jun 4, 2013 · 2 comments

Projects

None yet

2 participants

@yellincmp

Perhaps this is intentional, or perhaps I have just misunderstood how to use the route class, but it seems that when combining named regexes with trailing wildcards, Route::wildcardArgs() does not return the correct values.

For example, for:

$router->add('/:controller/:action/(allowed|words):words/*');

with route /testController/testAction/words/extra/fields :

$route->wildcardArgs();
//returns array('words')

If I change route to:

$router->add('/:controller/:action/:words/*');
$route->wildcardArgs();
//returns array('extra', 'fields'), as intended.
@deceze
Owner
deceze commented Jun 5, 2013

Good point. This is due to the way URLs are matched internally. It constructs one long regular expression to match against the URL, with wildcards being captured by a capture group. In your pattern, you are adding a capturing group yourself, which messes this process up. It should work (not tested) if you change your pattern to a non-capturing group:

(?:allowed|words):words

This is a case which the readme warns against as non-trivial regexen... :)

@deceze
Owner
deceze commented Jun 7, 2013

I committed a change that should allow grouping expressions together with wildcards.
Thanks for the report!

@deceze deceze closed this Jun 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment