diff --git a/lib/core.ts b/lib/core.ts index d0085608b..f469d5d82 100644 --- a/lib/core.ts +++ b/lib/core.ts @@ -742,7 +742,7 @@ function getLogger(logger?: Partial | false): Logger { throw new Error("logger must implement log, warn and error methods") } -const KEYWORD_NAME = /^[a-z_$][a-z0-9_$-:]*$/i +const KEYWORD_NAME = /^[a-z_$][a-z0-9_$:-]*$/i function checkKeyword(this: Ajv, keyword: string | string[], def?: KeywordDefinition): void { const {RULES} = this diff --git a/spec/keyword.spec.ts b/spec/keyword.spec.ts index 3508c2361..d27831b39 100644 --- a/spec/keyword.spec.ts +++ b/spec/keyword.spec.ts @@ -1099,6 +1099,10 @@ describe("User-defined keywords", () => { ajv.addKeyword("colons:are-valid") }) + should.throw(() => { + ajv.addKeyword("single-'quote-not-valid") + }, /invalid name/) + should.throw(() => { ajv.addKeyword("3-start-with-number-not-valid") }, /invalid name/)