JavaScriptCore:
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Dec 2007 06:08:24 +0000 (06:08 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Dec 2007 06:08:24 +0000 (06:08 +0000)
        Reviewed by Sam Weinig.

        - fix http://bugs.webkit.org/show_bug.cgi?id=16379
          REGRESSION(r28525): Failures in http/tests/xmlhttprequest/response-encoding.html and
          fast/dom/xmlhttprequest-html-response-encoding.html
          and <rdar://problem/5640230> REGRESSION (306A4-ToT): Access violation in PCRE function
          find_firstassertedchar

        Test: fast/js/regexp-find-first-asserted.html

        * pcre/pcre_compile.cpp:
        (compileBracket): Take out unnecessary initialization of out parameters.
        (branchFindFirstAssertedCharacter): Added. Broke out the half of the function that handles
        a branch.
        (bracketFindFirstAssertedCharacter): Renamed from find_firstassertedchar. Also removed the
        options parameter -- the caller can handle the options.
        (jsRegExpCompile): Changed call site to call the appropriate bracket or branch version of
        the find_firstassertedchar function. Also put the REQ_IGNORE_CASE code here instead of
        passing in the options.

LayoutTests:

        Reviewed by Sam Weinig.

        - test for http://bugs.webkit.org/show_bug.cgi?id=16379
          REGRESSION(r28525): Failures in http/tests/xmlhttprequest/response-encoding.html and
          fast/dom/xmlhttprequest-html-response-encoding.html
          and <rdar://problem/5640230> REGRESSION (306A4-ToT): Access violation in PCRE function
          find_firstassertedchar

        * fast/js/regexp-find-first-asserted-expected.txt: Added.
        * fast/js/regexp-find-first-asserted.html: Added.
        * fast/js/resources/regexp-find-first-asserted.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28609 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/pcre/pcre_compile.cpp
LayoutTests/ChangeLog
LayoutTests/fast/js/regexp-find-first-asserted-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/regexp-find-first-asserted.html [new file with mode: 0644]
LayoutTests/fast/js/resources/regexp-find-first-asserted.js [new file with mode: 0644]

index a4540f2..9238f0b 100644 (file)
@@ -1,3 +1,25 @@
+2007-12-10  Darin Adler  <darin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        - fix http://bugs.webkit.org/show_bug.cgi?id=16379
+          REGRESSION(r28525): Failures in http/tests/xmlhttprequest/response-encoding.html and
+          fast/dom/xmlhttprequest-html-response-encoding.html
+          and <rdar://problem/5640230> REGRESSION (306A4-ToT): Access violation in PCRE function
+          find_firstassertedchar
+
+        Test: fast/js/regexp-find-first-asserted.html
+
+        * pcre/pcre_compile.cpp:
+        (compileBracket): Take out unnecessary initialization of out parameters.
+        (branchFindFirstAssertedCharacter): Added. Broke out the half of the function that handles
+        a branch.
+        (bracketFindFirstAssertedCharacter): Renamed from find_firstassertedchar. Also removed the
+        options parameter -- the caller can handle the options.
+        (jsRegExpCompile): Changed call site to call the appropriate bracket or branch version of
+        the find_firstassertedchar function. Also put the REQ_IGNORE_CASE code here instead of
+        passing in the options.
+
 2007-12-10  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Sam Weinig.
index 9ff4bcb..a70577a 100644 (file)
@@ -154,6 +154,7 @@ struct CompileData {
 static bool compileBracket(int, int*, uschar**, const UChar**, const UChar*, ErrorCode*, int, int*, int*, CompileData&);
 static bool bracketIsAnchored(const uschar* code);
 static bool bracketNeedsLineStart(const uschar* code, unsigned captureMap, unsigned backrefMap);
+static int bracketFindFirstAssertedCharacter(const uschar* code, bool inassert);
 
 /*************************************************
 *            Handle escapes                      *
@@ -1943,8 +1944,8 @@ compileBracket(int options, int* brackets, uschar** codeptr,
     while (true) {
         /* Now compile the branch */
         
-        int branchfirstbyte = REQ_UNSET;
-        int branchreqbyte = REQ_UNSET;
+        int branchfirstbyte;
+        int branchreqbyte;
         if (!compileBranch(options, brackets, &code, &ptr, patternEnd, errorcodeptr,
                             &branchfirstbyte, &branchreqbyte, cd)) {
             *ptrptr = ptr;
@@ -2157,55 +2158,50 @@ Arguments:
 Returns:     -1 or the fixed first char
 */
 
-static int find_firstassertedchar(const uschar* code, int options, bool inassert)
+static int branchFindFirstAssertedCharacter(const uschar* code, bool inassert)
 {
-    int c = -1;
-    do {
-        const uschar* scode = firstSignificantOpCodeSkippingAssertions(code + 1 + LINK_SIZE);
-        int op = *scode;
-        
-        if (op >= OP_BRA)
-            op = OP_BRA;
-        
-        switch (op) {
-            default:
+    const uschar* scode = firstSignificantOpCodeSkippingAssertions(code);
+    int op = *scode;
+    
+    if (op >= OP_BRA)
+        op = OP_BRA;
+    
+    switch (op) {
+        default:
+            return -1;
+            
+        case OP_BRA:
+        case OP_ASSERT:
+        case OP_ONCE:
+            return bracketFindFirstAssertedCharacter(scode, op == OP_ASSERT);
+
+        case OP_EXACT:
+            scode += 2;
+            /* Fall through */
+
+        case OP_CHAR:
+        case OP_CHAR_IGNORING_CASE:
+        case OP_ASCII_CHAR:
+        case OP_ASCII_LETTER_IGNORING_CASE:
+        case OP_PLUS:
+        case OP_MINPLUS:
+            if (!inassert)
                 return -1;
-                
-            case OP_BRA:
-            case OP_ASSERT:
-            case OP_ONCE: {
-                int d;
-                if ((d = find_firstassertedchar(scode, options, op == OP_ASSERT)) < 0)
-                    return -1;
-                if (c < 0)
-                    c = d;
-                else if (c != d)
-                    return -1;
-                break;
-            }
-
-            case OP_EXACT:
-                scode += 2;
-                /* Fall through */
-
-            case OP_CHAR:
-            case OP_CHAR_IGNORING_CASE:
-            case OP_ASCII_CHAR:
-            case OP_ASCII_LETTER_IGNORING_CASE:
-            case OP_PLUS:
-            case OP_MINPLUS:
-                if (!inassert)
-                    return -1;
-                if (c < 0) {
-                    c = scode[1];
-                    if (options & IgnoreCaseOption)
-                        c |= REQ_IGNORE_CASE;
-                }
-                else if (c != scode[1])
-                    return -1;
-                break;
-        }
+            return scode[1];
+    }
+}
 
+static int bracketFindFirstAssertedCharacter(const uschar* code, bool inassert)
+{
+    int c = -1;
+    do {
+        int d = branchFindFirstAssertedCharacter(code + 1 + LINK_SIZE, inassert);
+        if (d < 0)
+            return -1;
+        if (c < 0)
+            c = d;
+        else if (c != d)
+            return -1;
         code += getOpcodeValueAtOffset(code, 1);
     } while (*code == OP_ALT);
     return c;
@@ -2823,8 +2819,12 @@ JSRegExp* jsRegExpCompile(const UChar* pattern, int patternLength,
     if (cd.needOuterBracket ? bracketIsAnchored(codeStart) : branchIsAnchored(codeStart))
         re->options |= IsAnchoredOption;
     else {
-        if (firstbyte < 0)
-            firstbyte = find_firstassertedchar(codeStart, re->options, false);
+        if (firstbyte < 0) {
+            firstbyte = (cd.needOuterBracket
+                    ? bracketFindFirstAssertedCharacter(codeStart, false)
+                    : branchFindFirstAssertedCharacter(codeStart, false))
+                | ((re->options & IgnoreCaseOption) ? REQ_IGNORE_CASE : 0);
+        }
         if (firstbyte >= 0) {
             int ch = firstbyte & 255;
             if (ch < 127) {
index 73d6af1..ced8629 100644 (file)
@@ -1,3 +1,17 @@
+2007-12-10  Darin Adler  <darin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        - test for http://bugs.webkit.org/show_bug.cgi?id=16379
+          REGRESSION(r28525): Failures in http/tests/xmlhttprequest/response-encoding.html and
+          fast/dom/xmlhttprequest-html-response-encoding.html
+          and <rdar://problem/5640230> REGRESSION (306A4-ToT): Access violation in PCRE function
+          find_firstassertedchar
+
+        * fast/js/regexp-find-first-asserted-expected.txt: Added.
+        * fast/js/regexp-find-first-asserted.html: Added.
+        * fast/js/resources/regexp-find-first-asserted.js: Added.
+
 2007-12-10  Antti Koivisto  <antti@apple.com>
 
         Reviewed by Adele.
diff --git a/LayoutTests/fast/js/regexp-find-first-asserted-expected.txt b/LayoutTests/fast/js/regexp-find-first-asserted-expected.txt
new file mode 100644 (file)
index 0000000..f2d24bd
--- /dev/null
@@ -0,0 +1,12 @@
+Tests some regular expressions that were doing the wrong thing with the "find first asserted" optimization.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS /.*<body>(.*)<\/body>.*/.exec("foo<body>bar</body>baz").toString() is "foo<body>bar</body>baz,bar"
+PASS /\s*<!--([sS]*)\/\/\s*-->\s*/.exec("<!--// -->").toString() is "<!--// -->,"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/regexp-find-first-asserted.html b/LayoutTests/fast/js/regexp-find-first-asserted.html
new file mode 100644 (file)
index 0000000..c76617a
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/regexp-find-first-asserted.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/js/resources/regexp-find-first-asserted.js b/LayoutTests/fast/js/resources/regexp-find-first-asserted.js
new file mode 100644 (file)
index 0000000..c2b9306
--- /dev/null
@@ -0,0 +1,10 @@
+description(
+'Tests some regular expressions that were doing the wrong thing with the "find first asserted" optimization.'
+);
+
+shouldBe('/.*<body>(.*)<\\/body>.*/.exec("foo<body>bar</body>baz").toString()', '"foo<body>bar</body>baz,bar"');
+shouldBe('/\\s*<!--([\s\S]*)\\/\\/\\s*-->\\s*/.exec("<!--// -->").toString()', '"<!--// -->,"');
+
+debug('');
+
+var successfullyParsed = true;