-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Router] allow to use \A and \z as regex start and end #37711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Router] allow to use \A and \z as regex start and end #37711
Conversation
9892b31
to
9362fa8
Compare
Travis failed with
|
@@ -546,6 +546,9 @@ public function compile() | |||
|
|||
private function sanitizeRequirement(string $key, string $regex) | |||
{ | |||
// Replace \A, \z with classic ^ and $ | |||
$regex = str_replace(['\A', '\z'], ['^', '$'], $regex); |
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.
There is no need to replace all occurrences, only the ones on the edges should be dealt with.
For \A
it's trivial, but for \z
, we should deal with escaped backslashes, eg \\z
should not be replaced.
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.
@nicolas-grekas Done. I also removed the type-casting for substr
result because after checking for empty string substr($regex, 1)
will always return string.
Note that this could be considered as a new feature. It should target master. |
9362fa8
to
9bf388d
Compare
8430e81
to
f752eee
Compare
Thank you @zlodes. |
@nicolas-grekas @zlodes
|
Some people are using
\A
and\z
as alternative for^
and$
for route requirements.E.g.: UUID pattern in ramsey/uuid (many routes broke after updating the lib):
ramsey/uuid@569e93a#diff-23c8536f7d61e7d839fd1c93ce0dd354L30-R31
References:
https://www.rexegg.com/regex-anchors.html#A
https://www.rexegg.com/regex-anchors.html#z
P.S.: It is my first PR into Symfony. Maybe I should fix something, just let me know.