Skip to content

Commit

Permalink
Merge pull request #40479 from SasinduDilshara/issue_39985
Browse files Browse the repository at this point in the history
Fix incorrect recovery for unicode general category values in regex
  • Loading branch information
rdulmina authored Jul 10, 2023
2 parents 5ba631c + faccd25 commit d08328e
Show file tree
Hide file tree
Showing 10 changed files with 3,334 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,14 @@ private STToken processReUnicodeGeneralCategoryAbbr() {
processAbbrWithOther();
break;
default:
while (!isEndOfUnicodePropertyEscape()) {
this.reader.advance();
}
reportLexerError(DiagnosticErrorCode.ERROR_INVALID_TOKEN_IN_REG_EXP);
break;
}

if (!isEndOfUnicodePropertyEscape()) {
while (!isEndOfUnicodePropertyEscape()) {
this.reader.advance();
}
reportLexerError(DiagnosticErrorCode.ERROR_INVALID_TOKEN_IN_REG_EXP);
}

return getRegExpText(SyntaxKind.RE_UNICODE_GENERAL_CATEGORY_NAME);
Expand All @@ -286,9 +290,7 @@ private void processAbbrWithLetter() {
case 'm':
case 'o':
this.reader.advance();
break;
default:
break;
return;
}
}

Expand All @@ -298,9 +300,7 @@ private void processAbbrWithMark() {
case 'c':
case 'e':
this.reader.advance();
break;
default:
break;
return;
}
}

Expand All @@ -310,9 +310,7 @@ private void processAbbrWithNumber() {
case 'l':
case 'o':
this.reader.advance();
break;
default:
break;
return;
}
}

Expand All @@ -323,9 +321,7 @@ private void processAbbrWithSymbol() {
case 'k':
case 'o':
this.reader.advance();
break;
default:
break;
return;
}
}

Expand All @@ -339,9 +335,7 @@ private void processAbbrWithPunctuation() {
case 'f':
case 'o':
this.reader.advance();
break;
default:
break;
return;
}
}

Expand All @@ -351,9 +345,7 @@ private void processAbbrWithSeparator() {
case 'l':
case 'p':
this.reader.advance();
break;
default:
break;
return;
}
}

Expand All @@ -364,9 +356,7 @@ private void processAbbrWithOther() {
case 'o':
case 'n':
this.reader.advance();
break;
default:
break;
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,12 @@ public void testInvalidRegExpWithBacktick() {
testFile("regexp-constructor-expr/regexp_constructor_source_53.bal",
"regexp-constructor-expr/regexp_constructor_assert_53.json");
}

@Test
public void testInvalidRegExpWithGeneralCategory() {
testFile("regexp-constructor-expr/regexp_constructor_source_54.bal",
"regexp-constructor-expr/regexp_constructor_assert_54.json");
testFile("regexp-constructor-expr/regexp_constructor_source_55.bal",
"regexp-constructor-expr/regexp_constructor_assert_55.json");
}
}

Large diffs are not rendered by default.

Loading

0 comments on commit d08328e

Please sign in to comment.