8281560: Matcher.hitEnd returns unexpected results in presence of CANON_EQ flag.

Reviewed-by: rriggs, lancea
This commit is contained in:
Ian Graves 2022-03-08 16:32:18 +00:00
parent 2549e55038
commit 3fc009be8a
2 changed files with 27 additions and 2 deletions

View file

@ -4005,8 +4005,9 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
} }
if (j < matcher.to) if (j < matcher.to)
return false; return false;
} else {
matcher.hitEnd = true;
} }
matcher.hitEnd = true;
return false; return false;
} }

View file

@ -4557,12 +4557,36 @@ public class RegExTest {
assertTrue(e.getMessage().contains("Bad intersection syntax")); assertTrue(e.getMessage().contains("Bad intersection syntax"));
} }
//This test is for 8281560
@Test
public static void prematureHitEndInNFCCharProperty() {
var testInput = "a1a1";
var pat1 = "(a+|1+)";
var pat2 = "([a]+|[1]+)";
var matcher1 = Pattern.compile(pat1, Pattern.CANON_EQ).matcher(testInput);
var matcher2 = Pattern.compile(pat2, Pattern.CANON_EQ).matcher(testInput);
ArrayList<Boolean> results1 = new ArrayList<>();
ArrayList<Boolean> results2 = new ArrayList<>();
while (matcher1.find()) {
results1.add(matcher1.hitEnd());
}
while (matcher2.find()) {
results2.add(matcher2.hitEnd());
}
assertEquals(results1, results2);
}
//This test is for 8281315 //This test is for 8281315
@Test @Test
public static void iOOBForCIBackrefs(){ public static void iOOBForCIBackrefs(){
String line = "\ud83d\udc95\ud83d\udc95\ud83d\udc95"; String line = "\ud83d\udc95\ud83d\udc95\ud83d\udc95";
var pattern2 = Pattern.compile("(?i)(.)\\1{2,}"); var pattern2 = Pattern.compile("(?i)(.)\\1{2,}");
assertTrue(pattern2.matcher(line).find()); assertTrue(pattern2.matcher(line).find());
} }
} }