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

schemafile was not valid: is not a regex #521

Closed
misery opened this issue Jan 30, 2025 · 3 comments
Closed

schemafile was not valid: is not a regex #521

misery opened this issue Jan 30, 2025 · 3 comments
Labels
question Further information is requested regular-expressions Related to the regex engines and modes

Comments

@misery
Copy link

misery commented Jan 30, 2025

Hi there,

since 0.31.0 our regex isn't accepted anymore. I don't see a problem in the regex.

Error: schemafile was not valid

SchemaError: "^[\\säÄöÖüÜßẞ\\w\\_\\'\\/\\-\\+\\*\\&\\<\\>\\(\\)\\,\\:\\.\\?\\!]+$" is not a 'regex'

Failed validating 'format' in metaschema['properties']['definitions']['additionalProperties']['$dynamicRef']['allOf'][1]['properties']['properties']['additionalProperties']['$dynamicRef']['allOf'][3]['properties']['pattern']:
    {'type': 'string', 'format': 'regex'}

On schema['definitions']['languageString']['properties']['']['pattern']:
    "^[\\säÄöÖüÜßẞ\\w\\_\\'\\/\\-\\+\\*\\&\\<\\>\\(\\)\\,\\:\\.\\?\\!]+$"
  in "/tmp/bla/lib/python3.13/site-packages/check_jsonschema/checker.py", line 56
  >>> return self._schema_loader.get_validator(

0.30.0 works without problems.

@edgarrmondragon
Copy link
Contributor

@misery have you tried 0.31.1?

@sirosen
Copy link
Member

sirosen commented Jan 30, 2025

Under v0.31.0 the default regex behavior changed from ECMAScript regexes (regress engine) to ECMAScript in Unicode Mode. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode#description)

Unicode Mode regexes are stricter about invalid escape sequences.
Net-net, I think this is generally a good thing, as it helps you write more correct code.
But it does mean that in cases like this one, where there are invalid escapes, those escapes will cause the regex to fail validation.

You can either remove the extra escapes or run with --regex-variant nonunicode to get the old behavior.

I walked through each escape in your expression and the following are not valid:

  • \_
  • \'
  • \&
  • \<
  • \>
  • \,
  • \:
  • \!

Therefore, your expression can be corrected to

"^[\\säÄöÖüÜßẞ\\w_'\\/\\-\\+\\*&<>\\(\\),:\\.\\?!]+$"

@sirosen sirosen added question Further information is requested regular-expressions Related to the regex engines and modes labels Jan 30, 2025
@misery
Copy link
Author

misery commented Jan 31, 2025

Thanks! I will go with the unicode version.

@misery misery closed this as completed Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested regular-expressions Related to the regex engines and modes
Projects
None yet
Development

No branches or pull requests

3 participants