Skip to content

Commit 894acbd

Browse files
authored
invalid value for patternproperties are validated by ajv (#576)
1 parent d35ff17 commit 894acbd

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,6 @@ function buildExtraObjectPropertiesSerializer (location) {
258258
for (const propertyKey in patternPropertiesSchema) {
259259
const propertyLocation = patternPropertiesLocation.getPropertyLocation(propertyKey)
260260

261-
try {
262-
RegExp(propertyKey)
263-
} catch (err) {
264-
const jsonPointer = propertyLocation.getSchemaRef()
265-
throw new Error(`${err.message}. Invalid pattern property regexp key ${propertyKey} at ${jsonPointer}`)
266-
}
267-
268261
code += `
269262
if (/${propertyKey.replace(/\\*\//g, '\\/')}/.test(key)) {
270263
${addComma}

test/patternProperties.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,21 @@ test('patternProperties - array coerce', (t) => {
148148
const incoercibleValues = { foo: 'true', ofoo: 0, objfoo: { tyrion: 'lannister' } }
149149
t.throws(() => stringify(incoercibleValues))
150150
})
151+
152+
test('patternProperties - fail on invalid regex, handled by ajv', (t) => {
153+
t.plan(1)
154+
155+
t.throws(() => build({
156+
title: 'check array coerce',
157+
type: 'object',
158+
properties: {},
159+
patternProperties: {
160+
'foo/\\': {
161+
type: 'array',
162+
items: {
163+
type: 'string'
164+
}
165+
}
166+
}
167+
}), new Error('schema is invalid: data/patternProperties must match format "regex"'))
168+
})

0 commit comments

Comments
 (0)