Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pattern with escaped '#' breaks pattern validation #174

Open
pjordaan opened this issue Aug 2, 2022 · 0 comments
Open

pattern with escaped '#' breaks pattern validation #174

pjordaan opened this issue Aug 2, 2022 · 0 comments

Comments

@pjordaan
Copy link

pjordaan commented Aug 2, 2022

I have a generated regular expression from PHP code and because it uses preg_quote() the final regular expression escapes the '#' even though it is not required

The regular expression that is generated in my JSON schema is:

^(?=(.*[a-z]){1,})(?=(.*[A-Z]){1,})(?=(.*[0-9]){1,})(?=(.*[\!@\#\$%\^&\*\(\)\-_\+\.]){1,}).{6,42}$

The pattern validation in class Pattern adds the # delimiter around it and replaces '#' with '\#' for the call to preg_match. Resulting in this preg_match pattern:

#^(?=(.*[a-z]){1,})(?=(.*[A-Z]){1,})(?=(.*[0-9]){1,})(?=(.*[\!@\\#\$%\^&\*\(\)\-_\+\.]){1,}).{6,42}$#u

This results in an error in the openapi psr7 validator: "preg_match(): Unknown modifier '\'"

preg_match(): Unknown modifier '\'

./vendor/league/openapi-psr7-validator/src/Schema/Keywords/Pattern.php:43
./vendor/league/openapi-psr7-validator/src/Schema/SchemaValidator.php:97
./vendor/league/openapi-psr7-validator/src/Schema/Keywords/Properties.php:85
./vendor/league/openapi-psr7-validator/src/Schema/SchemaValidator.php:139

Basically only # should be escaped in class Pattern if # is not already escaped. I could fix it for myself by unescaping it in the OpenAPI spec, but maybe it is a good idea to fix this in the validator as preg_quote() always escapes '#' even if you do not provide it as a delimiter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant