Skip to content

Cannot validate 'pattern' that contains a forward slash #18

Open
@ryangreenberg

Description

@ryangreenberg

Adding a pattern property to a schema is supposed to validate a value using the provided regular expression. This is done in generated code using StringPatternConstraint:

class StringPatternConstraint {
	public static function check(string $input, string $pattern, string $pointer): void {
		$match = \preg_match("/".$pattern."/", $input);
		/* ... */

However, this fails if $pattern contains a forward slash, because that collides with the / delimiter used here. A workaround is to use a double backslash when defining pattern in the schema so that it becomes \/ in the call to preg_match (this does change the meaning of the schema for other validators).

I thought that this was a case where we simply needed to use preg_quote, however that escapes all special characters in $pattern, not just the delimiter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions