ajv-validator / ajv

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
https://ajv.js.org
MIT License
13.87k stars 877 forks source link

'v' pattern flag support, log descriptive errors for invalid (failing to compile) regexp's #2458

Closed ekzobrain closed 4 months ago

ekzobrain commented 5 months ago

What version of Ajv you are you using? latest

What problem do you want to solve? Missing support for new 'v' regexp flag (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class#v-mode_character_class). Now regexp, that fail to compile, break validator totally. An exception is not descriptive, it's hard to find the location of a failing pattern keyword.

What do you think is the correct solution to problem? Add optional support for new 'v' regexp flag. Catch regexp initialization exceptions and log descriptive errors to console including invalid regexp itself. For example: "pattern 'xxx' at failed to compile with 'u' flag: . Check regexp validity or try changing compilation flag".

Will you be able to implement it? Yes, but need to discuss new option for enabling 'v' flag.

jasoniangreen commented 4 months ago

Hi @ekzobrain thanks for raising this. Can you prepare an example in runkit to help fast track investigation?

jasoniangreen commented 4 months ago

This is supported by the regexp keyword in the ajv-keywords project. https://ajv.js.org/packages/ajv-keywords.html#regexp