This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Enchance pattern to match character limit regex #8
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)
@acidvertigo |
@@ -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)); |
There was a problem hiding this comment.
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
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
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For example to giving this route
the given generateUri is: string '/it}' (length=4)
It should be: string '/it' (length=3)