Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a words blacklist rule that matches the word "and" in the first name to keep people from trying to register more than one person on a single form. However, I got a complaint about a registration being rejected and the first name field being highlighted in red when someone named "Wanda" tried to register.
I think the words blacklist rule is matching to a pattern instead of a word.
case "blacklist":
$blacklist = explode(',', $rule['data']);
$blacklist = array_map('trim', $blacklist);
$blacklist_regex = implode('|', $blacklist);
foreach ($items as $key => $val) {
if ($val != '' && (preg_match("/$blacklist_regex/i", $val))) {
$errors[$key] = _webform_validation_i18n_error_message($rule);
}
}
return $errors;
break;
It think you need to add "\b"`s around to the regex pattern to do a word matching:
preg_match("/\b$blacklist_regex\b/i", $val)
Comment | File | Size | Author |
---|---|---|---|
#6 | webform_validation_1162054_blacklist_words_fix.patch | 1.06 KB | Liam Morland |
#6 | webform_validation_1162054_blacklist_words_migrate.patch | 1.45 KB | Liam Morland |
#4 | webform_validation_1162054_blacklist_words.patch | 699 bytes | Liam Morland |
Comments
Comment #1
creeksideplayers CreditAttribution: creeksideplayers commentedCorrection, that should be
Comment #2
svendecabooterGood catch.
I'll have to test it some more, and think about the upgrade path for people that are already relying on the other behaviour...
Comment #3
DrewMathers CreditAttribution: DrewMathers commentedPerhaps you could provide a checkbox providing the option to match only whole words.
Comment #4
Liam MorlandThis change is backwards-incompatible; it will now match full words as documented, not patterns.
Fixed in 7841911.
Comment #5
Liam MorlandComment #6
Liam MorlandTwo more patches to make this actually work and migrate from the need to escape regex characters.
Comment #7
Liam MorlandCommitted in:
42b0989e8f7b9af71565f727995ee09d021d1215
ef372f66813fd3db1f3b2d679b4af5163579e08d
Comment #8
Liam MorlandComment #9
Liam MorlandDrupal 6 is no longer supported.