jdk/src/share/classes/java/util/regex/Pattern.java
changeset 11287 3db172a5433c
parent 9694 5cf41be509e5
child 12675 3b7d71495649
--- a/jdk/src/share/classes/java/util/regex/Pattern.java	Sat Dec 17 20:07:14 2011 +0000
+++ b/jdk/src/share/classes/java/util/regex/Pattern.java	Mon Dec 19 14:14:14 2011 -0800
@@ -1583,13 +1583,26 @@
             return;
         int j = i;
         i += 2;
-        int[] newtemp = new int[j + 2*(pLen-i) + 2];
+        int[] newtemp = new int[j + 3*(pLen-i) + 2];
         System.arraycopy(temp, 0, newtemp, 0, j);
 
         boolean inQuote = true;
+        boolean beginQuote = true;
         while (i < pLen) {
             int c = temp[i++];
-            if (! ASCII.isAscii(c) || ASCII.isAlnum(c)) {
+            if (!ASCII.isAscii(c) || ASCII.isAlpha(c)) {
+                newtemp[j++] = c;
+            } else if (ASCII.isDigit(c)) {
+                if (beginQuote) {
+                    /*
+                     * A unicode escape \[0xu] could be before this quote,
+                     * and we don't want this numeric char to processed as
+                     * part of the escape.
+                     */
+                    newtemp[j++] = '\\';
+                    newtemp[j++] = 'x';
+                    newtemp[j++] = '3';
+                }
                 newtemp[j++] = c;
             } else if (c != '\\') {
                 if (inQuote) newtemp[j++] = '\\';
@@ -1606,12 +1619,16 @@
                 if (temp[i] == 'Q') {
                     i++;
                     inQuote = true;
+                    beginQuote = true;
+                    continue;
                 } else {
                     newtemp[j++] = c;
                     if (i != pLen)
                         newtemp[j++] = temp[i++];
                 }
             }
+
+            beginQuote = false;
         }
 
         patternLength = j;