6817475: named-capturing group name started with digit causes PSE exception
authorsherman
Fri, 20 Mar 2009 16:22:59 -0700
changeset 2290 3a3bde061968
parent 2178 5a730fff4d0d
child 2291 140d84db0cd8
6817475: named-capturing group name started with digit causes PSE exception Summary: Need accept the digit as the first char of the group name Reviewed-by: alanb
jdk/src/share/classes/java/util/regex/Pattern.java
jdk/test/java/util/regex/RegExTest.java
--- a/jdk/src/share/classes/java/util/regex/Pattern.java	Wed Mar 04 09:26:41 2009 -0800
+++ b/jdk/src/share/classes/java/util/regex/Pattern.java	Fri Mar 20 16:22:59 2009 -0700
@@ -2567,7 +2567,8 @@
                 break;
             case '<':   // (?<xxx)  look behind
                 ch = read();
-                if (Character.isLetter(ch)) {     // named captured group
+                if (ASCII.isLower(ch) || ASCII.isUpper(ch) || ASCII.isDigit(ch)) {
+                    // named captured group
                     String name = groupname(ch);
                     if (namedGroups().containsKey(name))
                         throw error("Named capturing group <" + name
--- a/jdk/test/java/util/regex/RegExTest.java	Wed Mar 04 09:26:41 2009 -0800
+++ b/jdk/test/java/util/regex/RegExTest.java	Fri Mar 20 16:22:59 2009 -0700
@@ -3389,6 +3389,11 @@
               "gname",
               "yyy");
 
+        check(Pattern.compile("x+(?<8gname>y+)z+"),
+              "xxxyyyzzz",
+              "8gname",
+              "yyy");
+
         //backref
         Pattern pattern = Pattern.compile("(a*)bc\\1");
         check(pattern, "zzzaabcazzz", true);  // found "abca"