-
-
Notifications
You must be signed in to change notification settings - Fork 590
Validating "slug" and deny line ending and the end. #1148
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
Comments
The specification recommends but does not require you use JavaScript syntax. In particular, if you know all the consumers of your schema it may be you want to use Python syntax, and/or to put your flag inside the regex. |
Yes, but one of our schema consumer is a PHP project ;) So we can't use |
I'm not sure what else to offer then, you need to pick a common subset of regex syntax that works for what you're using.
Otherwise you might be interested in #1142 but that's something off in the future, and you'd still need to find a PHP regex implementation for Python or a JS implementation for PHP. |
Oh, is this possible? How? |
See https://docs.python.org/3/library/re.html#regular-expression-syntax, specifically |
EDIT: I tested I don't see a way to solve the problem. |
A "slug" regular expression can look like this:
r'^[-a-zA-Z0-9_]+\Z'
But
\Z
can't be used in JSON schema, because the regular expression syntax used from JavaScript and they doesn't support\Z
.Other libraries like https://github.com/swaggest/php-json-schema has a check for this case, e.g.:
https://github.com/swaggest/php-json-schema/blob/2d7b8e22a9de2680b8639404502df0b24b834da6/src/Constraint/Format.php#L111-L113
This is missing in jsonschema.
If we replace
\Z
with$
(e.g.:r'^[-a-zA-Z0-9_]+\Z'
) then a string with line ending likefoo\n
is valid because jsonschema seems not use usere.DOTALL
, isn't it?Or did i miss something?
tl;td;
\Z
should not be acceptedre.DOTALL
should be used for regexThe text was updated successfully, but these errors were encountered: