medic / cht-user-management

GNU Affero General Public License v3.0
3 stars 1 forks source link

Regex Validator Incorrectly Alters Email Addresses #82

Closed paulpascal closed 4 months ago

paulpascal commented 4 months ago

Description

The regex validator in validator-regex.ts is currently altering email addresses in a way that makes them invalid. This is due to the format on the input (validator-string.ts format), which replaces certain characters (including . and @) with spaces or removes them entirely.

Steps to Reproduce

  1. Add a contact property of type regex for email attribute:

    "contact_properties": [
        {
          "friendly_name": "Email address",
          "property_name": "email",
          "type": "regex",
          "parameter": "^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
          "required": true
        },
    ],
  2. Upload or add new item and define email attribute. Eg: johndoe@gmail.com

  3. The validator alters the email address to johndoegmail com, which is not a valid email address.

Expected Behavior

The regex validator should validate the email address, trim space around and retain all original characters, including . and @.

Actual Behavior

The regex validator alters the email address, replacing . with a space and removing @.

Screenshot 2024-02-27 at 03 37 53 Screenshot 2024-02-27 at 03 34 21

Suggested Fix