Skip to content

Commit

Permalink
Detect invalid unicode class specification
Browse files Browse the repository at this point in the history
Previously, the parser would unconditionally attempt to read the unicode
class spec after a \p or \P, even if the pattern is truncated and
invalid.

Fixes issue #72.
  • Loading branch information
sjamesr committed Oct 23, 2018
1 parent 06d4a72 commit 710be16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions java/com/google/re2j/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,10 @@ private boolean parseUnicodeClass(StringIterator t, CharClass cc) throws Pattern
if (c == 'P') {
sign = -1;
}
if (!t.more()) {
t.rewindTo(startPos);
throw new PatternSyntaxException(ERR_INVALID_CHAR_RANGE, t.rest());
}
c = t.pop();
String name;
if (c != '{') {
Expand Down
2 changes: 2 additions & 0 deletions javatests/com/google/re2j/RE2CompileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public static String[][] testData() {
{"a**", "invalid nested repetition operator: `**`"},
{"a*+", "invalid nested repetition operator: `*+`"},
{"\\x", "invalid escape sequence: `\\x`"},
{"\\p", "invalid character class range: `\\p`"},
{"\\p{", "invalid character class range: `\\p{`"}
};
}

Expand Down

0 comments on commit 710be16

Please sign in to comment.