8276694: Pattern trailing unescaped backslash causes internal error

Reviewed-by: jlaskey
This commit is contained in:
Masanori Yano 2022-01-11 22:37:15 +00:00 committed by Ian Graves
parent 36f41cbe11
commit 3aaa0982d8
2 changed files with 12 additions and 1 deletions

View file

@ -1795,6 +1795,8 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
if (patternLength != cursor) {
if (peek() == ')') {
throw error("Unmatched closing ')'");
} else if (cursor == patternLength + 1 && temp[patternLength - 1] == '\\') {
throw error("Unescaped trailing backslash");
} else {
throw error("Unexpected internal error");
}

View file

@ -35,7 +35,7 @@
* 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
* 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
* 8194667 8197462 8184692 8221431 8224789 8228352 8230829 8236034 8235812
* 8216332 8214245 8237599 8241055 8247546 8258259 8037397 8269753
* 8216332 8214245 8237599 8241055 8247546 8258259 8037397 8269753 8276694
*
* @library /test/lib
* @library /lib/testlibrary/java/lang
@ -4538,4 +4538,13 @@ public class RegExTest {
var sep = System.lineSeparator();
assertTrue(e.getMessage().contains(sep + "\t ^"));
}
//This test is for 8276694
@Test
public static void unescapedBackslash() {
String pattern = "\\";
var e = expectThrows(PatternSyntaxException.class, () ->
Pattern.compile(pattern));
assertTrue(e.getMessage().contains("Unescaped trailing backslash"));
}
}