Surrounded requirements regex by parenthesis #1110
Merged
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.
Currently, the regex used for requirements is automatically surrounded by characters
^
and$
(seeParamFetcher.php
code). It seems legit and very helpful, since wen can easily writeA+
to match at least oneA
, or evenA
if we expect only one occurence.Unfortunately, this helper may introduce a misunderstanding of what really happens in the case where we want to match an
A
or aB
character. Our first guess will beA|B
, but is is wrong. This requirement will produce the regex^A|B$
, matching all strings starting byA
or finishing byB
.This behavior is absolutely normal, this is not a bug, but IMHO it is counter-intuitive (then, dangerous). In the previous example, I should use parenthesis to reach my goal:
^(A|B)$
. So here my proposal, to add by default these surrounding parenthesis, in order to make requirement stringA|B
to match exactly oneA
, or exactly oneB
.According to my tests, even if you already used some😉 )
^
or$
in your regex, this should be retro-compatible. Nevertheless, this is a breaking change as soon as you were really expecting the stringA|B
to matchAbc
(or);TRUNCATE Users;#B
I updated corresponding tests in this PR, I am looking forward for your feedback, and thanks for all the work done for this library👍