-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[9.x] Patch regex rule parsing due to Rule::forEach()
#40941
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1d15509
Add failing test for `forEach` validation using regex
jbrooksuk 8256e57
Apply fixes from StyleCI
StyleCIBot c28499e
Wrap rule before processing and fix test case
stevebauman b16297e
Don't explode regex rules
stevebauman b3e6085
Refactor determination of regex validation rule
stevebauman 7fc4d44
Add more previously failing test cases
stevebauman befe010
Remove unneeded elseif
stevebauman 8738167
Add more tests with an expected failure test
stevebauman aa8f9d6
Add another test case and unify other tests
stevebauman ae6b101
Simplify string rule parsing
stevebauman 703bc37
formatting
taylorotwell 860b923
Add test for flattening rule arrays of arrays
stevebauman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
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.
I've used the spread operator to completely omit the third (
$limit
) parameter if the rule is not regex.If the rule is not a regex:
false
will be returned fromruleIsRegex()
array_filter
will then clearfalse
out of the array, resulting in an empty arrayI've added this, because
explode()
will take anull
,false
, or0
parameter and set the$limit
to1
.We want
$limit
to be1
when the rule is a regular expression, or$limit
to be completely omitted when the rule is not.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.
Can we adjust this code to actually explicitly pass an integer to
explode
?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.
Yes absolutely, one moment.
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.
I've simplified it to:
Since the
explode('|', $rule, 1)
will simply wrap the rule in an array. Let me know if you want me to change this. If I wanted to explicitly pass in an integer value, I'd have to usePHP_INT_MAX
for the default value (which looked a bit off -- not sure of your opinion on this):