changeset 16621:fcce22d93c3a

8158482: regex UNICODE_CHARACTER_CLASS flag cannot be disabled with an embedded flag expression Reviewed-by: bpb
author sherman
date Thu, 02 Jun 2016 14:03:50 -0700
parents 37b74e8f833d
children 03419f468c4b
files src/java.base/share/classes/java/util/regex/Pattern.java test/java/util/regex/RegExTest.java
diffstat 2 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/regex/Pattern.java	Thu Jun 02 12:25:17 2016 -0700
+++ b/src/java.base/share/classes/java/util/regex/Pattern.java	Thu Jun 02 14:03:50 2016 -0700
@@ -3194,6 +3194,7 @@
                 break;
             case 'U':
                 flags &= ~(UNICODE_CHARACTER_CLASS | UNICODE_CASE);
+                break;
             default:
                 return;
             }
--- a/test/java/util/regex/RegExTest.java	Thu Jun 02 12:25:17 2016 -0700
+++ b/test/java/util/regex/RegExTest.java	Thu Jun 02 14:03:50 2016 -0700
@@ -34,7 +34,7 @@
  * 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
+ * 6328855 6192895 6345469 6988218 6693451 7006761 8140212 8143282 8158482
  *
  * @library /lib/testlibrary
  * @build jdk.testlibrary.*
@@ -164,6 +164,7 @@
         groupCurlyBackoffTest();
         patternAsPredicate();
         invalidFlags();
+        embeddedFlags();
         grapheme();
         expoBacktracking();
 
@@ -4675,6 +4676,24 @@
         report("Invalid compile flags");
     }
 
+    // This test is for 8158482
+    private static void embeddedFlags() throws Exception {
+        try {
+            Pattern.compile("(?i).(?-i).");
+            Pattern.compile("(?m).(?-m).");
+            Pattern.compile("(?s).(?-s).");
+            Pattern.compile("(?d).(?-d).");
+            Pattern.compile("(?u).(?-u).");
+            Pattern.compile("(?c).(?-c).");
+            Pattern.compile("(?x).(?-x).");
+            Pattern.compile("(?U).(?-U).");
+            Pattern.compile("(?imsducxU).(?-imsducxU).");
+        } catch (PatternSyntaxException x) {
+            failCount++;
+        }
+        report("Embedded flags");
+    }
+
     private static void grapheme() throws Exception {
         Files.lines(Paths.get(System.getProperty("test.src", "."),
                               "GraphemeBreakTest.txt"))