Closed
Description
ajv: '^8.6.3'
ajv-keywords: '^5.0.0'
const Ajv = require('ajv').default
const ajv = new Ajv()
const ajvKeywords = require('ajv-keywords')
ajvKeywords(ajv)
const stringSchema = {
type: 'string',
pattern: 'a'
}
const stringSchema3 = {
$id: 'regexp',
type: 'string',
regexp: {
pattern: 'a',
flags: 'i'
}
}
console.log(ajv.validate(stringSchema, "a")) // true
console.log(ajv.validate(stringSchema3, "A")) // false
I expect the second logger to output true
Activity
[-]the regexp keyword Unexpected behavior[/-][+]the regexp keyword cashes pattern without taking flags into account[/+]epoberezkin commentedon Nov 21, 2021
this is specifically caused by the presence of the first schema, the regexp keyword looks up patterns in the same dictionary, by pattern, without taking flags into account... So this would do the same:
use RegExp string with flags as key for cached RegExp object, related…
34 remaining items