Skip to content

validation lib can erroneously split regex in validation check. #4180

Description

@robinsowell

Custom add-on, wants to validate uk style postal code via regex validation. rules:

'required|regex[/^[A-Z]{1,2}\d[A-Z\d]??\d[A-Z]{2}$/i]'

The regex works to match outside of EE, but doesn't in EE. After much research, the issue is that regex is getting split on the comma in {1,2}

I ended up logging a php error:

preg_match(): No ending delimiter ‘/’ found /Users/robinsowell/Sites/74/system/ee/ExpressionEngine/Service/Validation/Rule/Regex.php 24

Because the preg_match was using /^[A-Z]{1 as the regex. Because the full expression got exploded on the comma.

User tracked this down to “system/ee/ExpressionEngine/Service/Validation/Validator.php:301”

$parameters = explode(',', $parameters);

Which we need for enum, etc. but it jams that regex. May need a special case for $rule_name === “regex”, but it's thick enough in there I'd prefer not to make the change myself.

Activity

  1. added
    Bug: AcceptedBug has been confirmed, is reproducible, and ready to work on.
    on Mar 26, 2024
  2. changed the title [-]validation library can erroneaously split regex validation check.[/-] [+]validation lib can erroneously split regex in validation check.[/+] on Mar 26, 2024
  3. added a commit that references this issue on Mar 27, 2024
    e908b03
  4. intoeetive commented on Mar 27, 2024

    @intoeetive
    Contributor

    @robinsowell here's a fix for you, please review

  5. added a commit that references this issue on Mar 28, 2024
    d35e88c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug: AcceptedBug has been confirmed, is reproducible, and ready to work on.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions