Surrounded requirements regex by parenthesis - #1110
Merged
lsmith77 merged 1 commit intoSep 13, 2015
Merged
Conversation
Member
There was a problem hiding this comment.
please use a non-capturing group (adding a new capturing group makes it slower for all cases, and can break cases using advanced regex features)
Member
|
please add a test using a regex |
b-viguier
force-pushed
the
feature/regex-parenthesis
branch
from
September 8, 2015 15:54
2b489cf to
f1f0f8a
Compare
b-viguier
force-pushed
the
feature/regex-parenthesis
branch
from
September 8, 2015 19:50
f1f0f8a to
5445c75
Compare
Author
|
@stof Done |
lsmith77
added a commit
that referenced
this pull request
Sep 13, 2015
Surrounded requirements regex by parenthesis
Author
|
Nice! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, the regex used for requirements is automatically surrounded by characters
^and$(seeParamFetcher.phpcode). It seems legit and very helpful, since wen can easily writeA+to match at least oneA, or evenAif 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
Aor aBcharacter. Our first guess will beA|B, but is is wrong. This requirement will produce the regex^A|B$, matching all strings starting byAor 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|Bto 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|Bto 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 👍