Problem/Motivation
Using a regex with a space in it causes problems.
Steps to reproduce
Create a Regex validation that looks for the word "and": /(.*) and (.*)/
Submit a string that contains the letters "and", e.g. the name "Alexander".
What should happen:
The string is ignored and does not trigger a validation failure.
What actually happens:
The string fails validation.
Proposed resolution
Fix the bug.
Remaining tasks
Work out the cause of the bug.
User interface changes
Regex validation works as expected.
API changes
TBD
Data model changes
TBD
Issue fork field_validation-3391589
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
damienmckennaComment #3
damienmckennaFWIW I ended up building the logic I needed via a custom validator.
Comment #6
abhisekmazumdarThe Regex rule only supported "value must match the pattern" (allow-list) checking. There was no way to invert it to "value must NOT match" (block-list), which is what the original report needed.
MR!26 adds a checkbox to invert the match. Checked by default, so existing rules are unaffected.
How to test
/(.*) and (.*)/, checkbox unchecked.Also added automated tests covering this. Marking Needs Review.
Comment #7
arianraeesi commentedComment #8
arianraeesi commentedComment #9
arianraeesi commentedComment #10
kieran.cottManual testing
Configure rule
1. Created field validation rule on Article bundle (Title, Pattern
/(.*) and (.*)/):'Value must match the pattern to be valid': Unchecked
Verify persistence
1. Click 'Edit' on rule
2. 'Value must match the pattern to be valid' - still unchecked
Verify stored value
1.
drush cget field_validation.rule_set.node_article field_validation_rules<code>:data: match: falseTest the regression
Alexander - article saves successfully
Band Aid - article saves successfully
Bill and Ted - submission rejected
Salt and pepper - submission rejected
Test normal matching
1. Edit the validation rule on Article bundle (Title, Pattern
/^[A-Za-z]+$/):'Value must match the pattern to be valid': Checked
Alphabetic - article saves successfully
1234 - submission rejected
Letters123 - submission rejected
Test direct validation
1. Edit the validation rule on Article bundle (Title, Pattern
/(.*) and (.*)/):'Value must match the pattern to be valid': Unchecked
'Validate mode': Direct
Alexander - article saves successfully
Band Aid - article saves successfully
Bill and Ted - submission rejected
Salt and pepper - submission rejected
Testing passed.
Comment #12
abhisekmazumdarMR !26 is merged.
The Regex rule only supported "value must match the pattern" checking, so there was no way to flag values that contain a pattern like "and" without also failing values like "Alexander" that merely contain the letters. This adds an invert-match option so the rule can go either way.
Thanks all.
Comment #13
abhisekmazumdar