Skip to content

Commit 3fc009b

Browse files
author
Ian Graves
committed
8281560: Matcher.hitEnd returns unexpected results in presence of CANON_EQ flag.
Reviewed-by: rriggs, lancea
1 parent 2549e55 commit 3fc009b

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/java.base/share/classes/java/util/regex/Pattern.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4005,8 +4005,9 @@ boolean match(Matcher matcher, int i, CharSequence seq) {
40054005
}
40064006
if (j < matcher.to)
40074007
return false;
4008+
} else {
4009+
matcher.hitEnd = true;
40084010
}
4009-
matcher.hitEnd = true;
40104011
return false;
40114012
}
40124013

test/jdk/java/util/regex/RegExTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4557,12 +4557,36 @@ public static void badIntersectionSyntax() {
45574557
assertTrue(e.getMessage().contains("Bad intersection syntax"));
45584558
}
45594559

4560+
//This test is for 8281560
4561+
@Test
4562+
public static void prematureHitEndInNFCCharProperty() {
4563+
var testInput = "a1a1";
4564+
var pat1 = "(a+|1+)";
4565+
var pat2 = "([a]+|[1]+)";
4566+
4567+
var matcher1 = Pattern.compile(pat1, Pattern.CANON_EQ).matcher(testInput);
4568+
var matcher2 = Pattern.compile(pat2, Pattern.CANON_EQ).matcher(testInput);
4569+
4570+
ArrayList<Boolean> results1 = new ArrayList<>();
4571+
ArrayList<Boolean> results2 = new ArrayList<>();
4572+
4573+
while (matcher1.find()) {
4574+
results1.add(matcher1.hitEnd());
4575+
}
4576+
4577+
while (matcher2.find()) {
4578+
results2.add(matcher2.hitEnd());
4579+
}
4580+
4581+
assertEquals(results1, results2);
4582+
}
4583+
45604584
//This test is for 8281315
45614585
@Test
45624586
public static void iOOBForCIBackrefs(){
45634587
String line = "\ud83d\udc95\ud83d\udc95\ud83d\udc95";
45644588
var pattern2 = Pattern.compile("(?i)(.)\\1{2,}");
45654589
assertTrue(pattern2.matcher(line).find());
4566-
45674590
}
45684591
}
4592+

0 commit comments

Comments
 (0)