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

Regex flag when specifying a pattern #36

Open
eric-bonucci opened this issue Sep 30, 2020 · 1 comment
Open

Regex flag when specifying a pattern #36

eric-bonucci opened this issue Sep 30, 2020 · 1 comment

Comments

@eric-bonucci
Copy link

Hi,

When specifying a pattern using a regular expression, one can not use the case insensitive flag in the regex.

Reproducible example (using dplyr):

library(dplyr)
'
{
	"type": "object",
	"properties":{
	  "product_type": {
      "type": ["string"],
      "pattern": "^(?i)test$"
    }
	},
  "required": [
	  "product_type"
  ],
}
' %>% jsonvalidate::json_validator(engine = "ajv") -> validator
@richfitz
Copy link
Member

Sorry for missing this issue for a year 😱

This appears to be an issue with the underling Ajv engine:

const Ajv = require('ajv');
const opts = {allErrors: true,
            verbose: true,
            unicodeRegExp: true,
            strict: true};
const obj = new Ajv(opts);
const schema = {
    "type": "object",
    "properties":{
	"product_type": {
            "type": ["string"],
            "pattern": "^(?i)test$"
        }
    },
    "required": [
	"product_type"
    ]
}
obj.compile(schema)

which errors with

Thrown:
SyntaxError: Invalid regular expression: /^(?i)test$/: Invalid group

so the error reported is faithful to the underlying engine.

I found this issue on the Ajv repo: ajv-validator/ajv#101, though the link within to "defining custom keywords" is broken - I think this is the relevant page now: https://ajv.js.org/keywords.html

In short, this looks quite hard to support unfortunately

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

2 participants