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

Not ECMA-262 Compliant #277

Open
jamesgoodhouse opened this issue Oct 25, 2019 · 1 comment
Open

Not ECMA-262 Compliant #277

jamesgoodhouse opened this issue Oct 25, 2019 · 1 comment
Labels

Comments

@jamesgoodhouse
Copy link

JSON schema regexp's are in the ECMA-262 dialect, but Go's regexp package does not meet this standard (it is to the RE2 standard to keep things O(n)). This means it's not possible to meet the standard for a JSON schema using this package.

A possible solution would be implement an interface for a regexp engine, default to Go's regexp package, and allow the user to pass their own engine in if they need extended capabilities not offered by the default engine. A quick search shows there is at least other Go regexp engine that exists (unfortunately is based on the .NET engine). It's possible one could be created that matches the ECMA-262 dialect.

@jamesgoodhouse jamesgoodhouse changed the title Not ECMA 262 Compliant Not ECMA-262 Compliant Oct 25, 2019
@johandorland
Copy link
Collaborator

johandorland commented Oct 31, 2019

To quote the JSON schema spec:

Keywords MAY use regular expressions to express constraints, or constrain the instance value to be a regular expression. These regular expressions SHOULD be valid according to the regular expression dialect described in ECMA 262, section 15.10.1.

As it says SHOULD and not MUST it's not required to use ECMA 262 and not having (easy) access to an ECMA 262 implementation is a pretty good reason to deviate. Using the standard library's regex engine is the most sane default in my opinion. Having said that it would be nice to make the regex engine pluggable so someone could use the .NET engine you referenced or maybe even go through more hoops and actually use an ECMA 262 engine via CGO if they really need it.

PRs are welcome and appreciated, otherwise this will have to wait until I find some time to work on this sort of stuff.

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

No branches or pull requests

2 participants