OpenJDK / jdk / jdk
changeset 45888:ae448cf92e00
8184706: Matcher doesn't indicate hitEnd after matching \u0D with \R at EOL
Reviewed-by: sherman
author | igerasim |
---|---|
date | Sat, 15 Jul 2017 14:01:49 -0700 |
parents | 0db4957afd51 |
children | 605589f46d2a |
files | jdk/src/java.base/share/classes/java/util/regex/Pattern.java jdk/test/java/util/regex/RegExTest.java |
diffstat | 2 files changed, 28 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/jdk/src/java.base/share/classes/java/util/regex/Pattern.java Fri Jul 14 10:42:46 2017 -0700 +++ b/jdk/src/java.base/share/classes/java/util/regex/Pattern.java Sat Jul 15 14:01:49 2017 -0700 @@ -3887,9 +3887,13 @@ return next.match(matcher, i + 1, seq); if (ch == 0x0D) { i++; - if (i < matcher.to && seq.charAt(i) == 0x0A && - next.match(matcher, i + 1, seq)) { - return true; + if (i < matcher.to) { + if (seq.charAt(i) == 0x0A && + next.match(matcher, i + 1, seq)) { + return true; + } + } else { + matcher.hitEnd = true; } return next.match(matcher, i, seq); }
--- a/jdk/test/java/util/regex/RegExTest.java Fri Jul 14 10:42:46 2017 -0700 +++ b/jdk/test/java/util/regex/RegExTest.java Sat Jul 15 14:01:49 2017 -0700 @@ -33,9 +33,8 @@ * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066 * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590 * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819 - * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 - * 6328855 6192895 6345469 6988218 6693451 7006761 8140212 8143282 8158482 - * 8176029 + * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895 + * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706 * * @library /test/lib * @build jdk.test.lib.RandomFactory @@ -470,7 +469,25 @@ m.find(); if (!m.hitEnd()) failCount++; - report("hitEnd from a Slice"); + + // 8184706: Matching u+0d at EOL against \R should hit-end + p = Pattern.compile("...\\R"); + m = p.matcher("cat" + (char)0x0a); + m.find(); + if (m.hitEnd()) + failCount++; + + m = p.matcher("cat" + (char)0x0d); + m.find(); + if (!m.hitEnd()) + failCount++; + + m = p.matcher("cat" + (char)0x0d + (char)0x0a); + m.find(); + if (m.hitEnd()) + failCount++; + + report("hitEnd"); } // This is for bug 4997476