8037397: RegEx pattern matching loses character class after intersection (&&) operator

Reviewed-by: rriggs
This commit is contained in:
Ian Graves 2021-04-21 15:45:52 +00:00 committed by Roger Riggs
parent 07a7510d87
commit b337f63361
2 changed files with 41 additions and 3 deletions

View File

@ -2663,7 +2663,11 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
right = right.union(clazz(true));
} else { // abc&&def
unread();
right = clazz(false);
if (right == null) {
right = clazz(false);
} else {
right = right.union(clazz(false));
}
}
ch = peek();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,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
* 8216332 8214245 8237599 8241055 8247546 8258259 8037397
*
* @library /test/lib
* @library /lib/testlibrary/java/lang
@ -71,6 +71,7 @@ import java.util.regex.Matcher;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import jdk.test.lib.RandomFactory;
@ -196,6 +197,8 @@ public class RegExTest {
lineBreakWithQuantifier();
caseInsensitivePMatch();
surrogatePairOverlapRegion();
droppedClassesWithIntersection();
if (failure) {
throw new
@ -5256,4 +5259,35 @@ public class RegExTest {
}
report("surrogatePairOverlapRegion");
}
//This test is for 8037397
private static void droppedClassesWithIntersection() {
String rx = "[A-Z&&[A-Z]0-9]";
String ry = "[A-Z&&[A-F][G-Z]0-9]";
Stream<Character> letterChars = IntStream.range('A', 'Z').mapToObj((i) -> (char) i);
Stream<Character> digitChars = IntStream.range('0', '9').mapToObj((i) -> (char) i);
boolean letterCharsMatch = letterChars.allMatch((ch) -> {
String chString = ch.toString();
return chString.matches(rx) && chString.matches(ry);
});
boolean digitCharsDontMatch = digitChars.noneMatch((ch) -> {
String chString = ch.toString();
return chString.matches(rx) && chString.matches(ry);
});
if (!letterCharsMatch) {
failCount++;
System.out.println("Compiling intersection pattern is dropping a character class in its matcher");
}
if (!digitCharsDontMatch) {
failCount++;
System.out.println("Compiling intersection pattern is matching digits where it should not");
}
}
}