changeset 1010:3b6d7e15ccd9

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
author sherman
date Fri, 20 Mar 2009 16:22:59 -0700
parents 6568cd51ae12
children c6b37e92e387
files src/share/classes/java/util/regex/Pattern.java test/java/util/regex/RegExTest.java
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/regex/Pattern.java	Wed Mar 04 09:26:41 2009 -0800
+++ b/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/test/java/util/regex/RegExTest.java	Wed Mar 04 09:26:41 2009 -0800
+++ b/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"