-
Notifications
You must be signed in to change notification settings - Fork 54
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
JSON Schema Regex issues #47
Comments
Thankfully the spec has guidance on regex interop. Specifically:
So, basically, when writing a schema, try to keep the regex simple. But we can get a little more specific b/c you're dealing in go-to-js regex conversion. Javascript is supposed to use ECMA-262 regex, and go's
Looks like the two biggest difference on the "basic features" are I consider it a bug that you didn't get a good, human-readable error when regex parsing fails due to these limitations. If you have any interest in filing a PR that adds a test and a better error message, I'd be deeply appreciative. A great place to start would be returning a better error message here: Line 258 in 094d15a
|
The implementation uses package This problem is not even documented in the README or in package documentation. |
I agree that this package is not 100% compliant with the spec, but not for this reason. The section from the spec you're quoting:
I interpret the use of the word SHOULD in the above sentence to mean that both json schema implementers and spec authors SHOULD aim for ECMA-262. If fully implementing ECMA-262 were required to be considered part of the spec, I would expect the above sentence to use Doing a full ECMA-262 spec implementation would require an extra import that isn't in the go standard library. We haven't had anyone ask for it yet, and I prefer to stick to standard library imports whenever possible, but if this is a major sticking point for people using this package, I'd be happy to talk through it.
We'd gladly accept a pull request that documents the difference in regex parsing. |
Yeah, regexes are a bit of an interoperability nightmare. As an example, you'll note that There's no great solution, the language in the spec is intended to indicate that JSON Schema inherits the same interoperability problems, and we pick one recommended standard with the understanding that none of the standards are universally supported. |
I also ran into this issue when using negative lookbehind in the regex pattern, and it took me a while to understand what the problem was. Any chance we could get clearer error message when this occurs? |
The Otto project (a JavaScript interpreter) has a function that fixes some incompatibilities between Go regexp and JS regexp. But that will not add lookbehind. |
Module |
I am currently working with a JSON Schema that is shared with a frontend application for building and validating a data structure that then get's passed to my backend go service which also uses the schema for data validation. Now the issue I'm having is the schema in question is using the regex
pattern
keyword for data validation and this works fine when its in the js world, however when using this schema with this jsonschema package I get the following error:Now from my research go uses a different regex engine under the hood. And I am wondering how other deal with this when sharing a schema between different languages such as go and js?
The text was updated successfully, but these errors were encountered: