Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy 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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
9892b31 to9362fa8Comparezlodes commentedJul 30, 2020
Travis failed with |
| privatefunctionsanitizeRequirement(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 forsubstr result because after checking for empty stringsubstr($regex, 1) will always return string.
nicolas-grekas commentedJul 30, 2020
Note that this could be considered as a new feature. It should target master. |
9362fa8 to9bf388dCompareUh oh!
There was an error while loading.Please reload this page.
8430e81 tof752eeeComparefabpot commentedJul 31, 2020
Thank you@zlodes. |
rvitaliy commentedJul 31, 2020
@nicolas-grekas@zlodes
|
Uh oh!
There was an error while loading.Please reload this page.
Some people are using
\Aand\zas 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.