Skip to content

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

@robinsowell

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.

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