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)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

creeksideplayers’s picture

Correction, that should be

preg_match("/\b($blacklist_regex)\b/i", $val)
svendecabooter’s picture

Assigned: Unassigned » svendecabooter

Good 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...

DrewMathers’s picture

Perhaps you could provide a checkbox providing the option to match only whole words.

Liam Morland’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Patch (to be ported) » Fixed
FileSize
699 bytes

This change is backwards-incompatible; it will now match full words as documented, not patterns.

Fixed in 7841911.

Liam Morland’s picture

Version: 6.x-1.4 » 6.x-1.x-dev
Status: Active » Patch (to be ported)
Liam Morland’s picture

Two more patches to make this actually work and migrate from the need to escape regex characters.

Liam Morland’s picture

Committed in:
42b0989e8f7b9af71565f727995ee09d021d1215
ef372f66813fd3db1f3b2d679b4af5163579e08d

Liam Morland’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Fixed » Patch (to be ported)
Liam Morland’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes
Status: Patch (to be ported) » Closed (fixed)

Drupal 6 is no longer supported.