Skip to content

Commit 4d43e6e

Browse files
authored
feat: Notify Invalid RegExp Patterns (#261)
* report problem if extendedRegExp catches an error * only report invalid regex if needed * add test for invalid patterns * no optional chaining * ignore invalid regex
1 parent 24f360b commit 4d43e6e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/parser/jsonParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ function validate(n: ASTNode | undefined, schema: JSONSchema, validationResult:
718718

719719
if (isString(schema.pattern)) {
720720
const regex = extendedRegExp(schema.pattern);
721-
if (!(regex?.test(node.value))) {
721+
if (regex && !(regex.test(node.value))) {
722722
validationResult.problems.push({
723723
location: { offset: node.offset, length: node.length },
724724
message: schema.patternErrorMessage || schema.errorMessage || l10n.t('String does not match the pattern of "{0}".', schema.pattern)

src/test/parser.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,18 @@ suite('JSON Parser', () => {
609609

610610
assert.strictEqual(semanticErrors!.length, 0);
611611

612+
semanticErrors = validate2(jsonDoc, textDoc, {
613+
type: 'object',
614+
properties: {
615+
"one": {
616+
type: 'string',
617+
pattern: '*+ (invalid pattern)',
618+
}
619+
}
620+
});
621+
622+
assert.strictEqual(semanticErrors!.length, 0);
623+
612624
semanticErrors = validate2(jsonDoc, textDoc, {
613625
type: 'object',
614626
properties: {

0 commit comments

Comments
 (0)