Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Enchance pattern to match character limit regex #8

Merged
merged 11 commits into from
May 3, 2016

Conversation

acidvertigo
Copy link
Contributor

@acidvertigo acidvertigo commented Jan 26, 2016

For example to giving this route

'routes' => [
        [
            'name' => 'home',
            'path' => '/{locale:[a-z]{2}}',
            'middleware' => App\Action\HomePageAction::class,
            'allowed_methods' => ['GET'],
        ],

the given generateUri is: string '/it}' (length=4)

It should be: string '/it' (length=3)

For example to giving this route

'routes' => [
        [
            'name' => 'home',
            'path' => '/{locale:[a-z]{2}}',
            'middleware' => App\Action\HomePageAction::class,
            'allowed_methods' => ['GET'],
        ],

the given generateUri is: string '/it}' (length=4)

It should be: string '/it' (length=3)
@pine3ree
Copy link
Contributor

@acidvertigo
@weierophinney
Hello, i believe that the regex pattern capable of handling regex constraints such as{x,y}, should be using the FastRoute\RouteParser\Std::VARIABLE_REGEX and specifically the non-capturing group, while the first part is substituted via sprintf (%s with $key)

@@ -142,7 +142,7 @@ public function generateUri($name, array $substitutions = [])
$path = $route->getPath();

foreach ($substitutions as $key => $value) {
$pattern = sprintf('#\{%s(:[^}]+)?\}#', preg_quote($key));
$pattern = sprintf('#\{%s(:[^}]+)?\}}#', preg_quote($key));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is problematic, as it assumes all placeholders use {} quantifiers internally; it's literally matching for }} as the closing delimiter, when some will only be }.

@weierophinney weierophinney merged commit a1df61a into zendframework:master May 3, 2016
weierophinney added a commit that referenced this pull request May 3, 2016
Enchance pattern to match character limit regex
weierophinney added a commit that referenced this pull request May 3, 2016
This patch does the following:

- Creates a data provider for the test case `testCanGenerateUriFromRoutes`, which allows for better segregation of tests.
- Fixes a test expectation; the newest data set was passing `2` for a substitution, but testing against an expectation of `42`.
- Updates the FasteRouteRouter implementation to use a similar solution to `FastRoute\RouteParser\Std::VARIABLE_REGEX` for matching variable substitutions (thanks for the suggestion, @pine3ree !))
weierophinney added a commit that referenced this pull request May 3, 2016
weierophinney added a commit that referenced this pull request May 3, 2016
weierophinney added a commit that referenced this pull request May 3, 2016
@weierophinney weierophinney self-assigned this May 3, 2016
@weierophinney weierophinney added this to the 1.1.1 milestone May 3, 2016
@weierophinney
Copy link
Member

I've incorporated the suggestion from @pine3ree , and also updated the tests to use a data provider to better segregate the various URI test cases.

@acidvertigo acidvertigo deleted the patch-1 branch July 6, 2016 22:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants