diff --git a/src/parser/jsonParser.ts b/src/parser/jsonParser.ts index 33e3b80d..14fd3876 100644 --- a/src/parser/jsonParser.ts +++ b/src/parser/jsonParser.ts @@ -718,7 +718,7 @@ function validate(n: ASTNode | undefined, schema: JSONSchema, validationResult: if (isString(schema.pattern)) { const regex = extendedRegExp(schema.pattern); - if (!(regex?.test(node.value))) { + if (regex && !(regex.test(node.value))) { validationResult.problems.push({ location: { offset: node.offset, length: node.length }, message: schema.patternErrorMessage || schema.errorMessage || l10n.t('String does not match the pattern of "{0}".', schema.pattern) diff --git a/src/test/parser.test.ts b/src/test/parser.test.ts index e6cf4e09..ca1a92fb 100644 --- a/src/test/parser.test.ts +++ b/src/test/parser.test.ts @@ -609,6 +609,18 @@ suite('JSON Parser', () => { assert.strictEqual(semanticErrors!.length, 0); + semanticErrors = validate2(jsonDoc, textDoc, { + type: 'object', + properties: { + "one": { + type: 'string', + pattern: '*+ (invalid pattern)', + } + } + }); + + assert.strictEqual(semanticErrors!.length, 0); + semanticErrors = validate2(jsonDoc, textDoc, { type: 'object', properties: {