JavaScriptCore:
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Jan 2009 21:51:38 +0000 (21:51 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Jan 2009 21:51:38 +0000 (21:51 +0000)
2009-01-16  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Darin Adler.

        Fixed <rdar://problem/6452301> REGRESSION: Latest WebKit nightlies
        turn "c" into "" when stripping \\c_ character

        * wrec/WRECParser.cpp:
        (JSC::WREC::Parser::consumeEscape): Mimic a Firefox quirk when parsing
        control escapes inside character classes.

LayoutTests:

2009-01-16  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Darin Adler.

        Added tests for <rdar://problem/6452301> REGRESSION: Latest WebKit
        nightlies turn "c" into "" when stripping \\c_ character

        * fast/regex/malformed-escapes-expected.txt:
        * fast/regex/resources/malformed-escapes.js:

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

JavaScriptCore/ChangeLog
JavaScriptCore/pcre/pcre_compile.cpp
JavaScriptCore/wrec/WRECParser.cpp
LayoutTests/ChangeLog
LayoutTests/fast/regex/malformed-escapes-expected.txt
LayoutTests/fast/regex/resources/malformed-escapes.js

index b17e46a..15584e2 100644 (file)
@@ -1,3 +1,14 @@
+2009-01-16  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Darin Adler.
+        
+        Fixed <rdar://problem/6452301> REGRESSION: Latest WebKit nightlies
+        turn "c" into "" when stripping \\c_ character
+
+        * wrec/WRECParser.cpp:
+        (JSC::WREC::Parser::consumeEscape): Mimic a Firefox quirk when parsing
+        control escapes inside character classes.
+
 2009-01-16  Adam Roben  <aroben@apple.com>
 
         Windows build fix
index d0ff510..f162d18 100644 (file)
@@ -303,7 +303,10 @@ static int checkEscape(const UChar** ptrPtr, const UChar* patternEnd, ErrorCode*
                 }
                 
                 c = *ptr;
-                if (!isASCIIAlpha(c)) {
+
+                /* To match Firefox, inside a character class, we also accept
+                   numbers and '_' as control characters */
+                if ((!isClass && !isASCIIAlpha(c)) || (!isASCIIAlphanumeric(c) && c != '_')) {
                     c = '\\';
                     ptr -= 2;
                     break;
index 640e611..1709bf9 100644 (file)
@@ -461,7 +461,9 @@ Escape Parser::consumeEscape(bool inCharacterClass)
         consume();
         
         int control = consume();
-        if (!isASCIIAlpha(control)) {
+        // To match Firefox, inside a character class, we also accept numbers
+        // and '_' as control characters.
+        if ((!inCharacterClass && !isASCIIAlpha(control)) || (!isASCIIAlphanumeric(control) && control != '_')) {
             state.restore();
             return PatternCharacterEscape('\\');
         }
index c26be8c..9f4809b 100644 (file)
@@ -1,3 +1,13 @@
+2009-01-16  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Darin Adler.
+        
+        Added tests for <rdar://problem/6452301> REGRESSION: Latest WebKit
+        nightlies turn "c" into "" when stripping \\c_ character
+
+        * fast/regex/malformed-escapes-expected.txt:
+        * fast/regex/resources/malformed-escapes.js:
+
 2009-01-16  Chris Fleizach  <cfleizach@apple.com>
 
         Reviewed by Beth Dakin.
index 70ab3f3..e369e23 100644 (file)
@@ -27,6 +27,15 @@ PASS regexp.lastIndex is 1
 Testing regexp: /\8/gm
 PASS regexp.test('\\8') is true
 PASS regexp.lastIndex is 2
+
+Testing regexp: /^[\c]$/
+PASS regexp.test('c') is true
+
+Testing regexp: /^[\c_]$/
+PASS regexp.test('c') is false
+
+Testing regexp: /^[\c]]$/
+PASS regexp.test('c]') is true
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 1bcaeec..ddb7446 100644 (file)
@@ -34,4 +34,16 @@ debug("\nTesting regexp: " + regexp);
 shouldBeTrue("regexp.test('\\\\8')");
 shouldBe("regexp.lastIndex", "2");
 
+regexp = /^[\c]$/;
+debug("\nTesting regexp: " + regexp);
+shouldBeTrue("regexp.test('c')");
+
+regexp = /^[\c_]$/;
+debug("\nTesting regexp: " + regexp);
+shouldBeFalse("regexp.test('c')");
+
+regexp = /^[\c]]$/;
+debug("\nTesting regexp: " + regexp);
+shouldBeTrue("regexp.test('c]')");
+
 var successfullyParsed = true;