Title: [151510] trunk
Revision
151510
Author
ser...@webkit.org
Date
2013-06-12 10:23:31 -0700 (Wed, 12 Jun 2013)

Log Message

Skipping {}, () and [] blocks while error recovering in CSS
https://bugs.webkit.org/show_bug.cgi?id=116071

Reviewed by Darin Adler.

>From Blink r150201 and r150755 by <se...@chromium.org>

Source/WebCore:

Test: fast/css/parsing-expr-error-recovery.html

The CSS parser should properly recover from invalid {}, () and []
blocks skipping them instead of discarding the whole declaration
as invalid. This merge is actually made of two different changes
from Blink, the original one that fixes the bug and another one
which refactors a bit the code making it more legible.

* css/CSSGrammar.y.in:

LayoutTests:

* fast/css/parsing-expr-error-recovery-expected.txt: Added.
* fast/css/parsing-expr-error-recovery.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (151509 => 151510)


--- trunk/LayoutTests/ChangeLog	2013-06-12 17:22:57 UTC (rev 151509)
+++ trunk/LayoutTests/ChangeLog	2013-06-12 17:23:31 UTC (rev 151510)
@@ -1,5 +1,17 @@
 2013-06-12  Sergio Villar Senin  <svil...@igalia.com>
 
+        Skipping {}, () and [] blocks while error recovering in CSS
+        https://bugs.webkit.org/show_bug.cgi?id=116071
+
+        Reviewed by Darin Adler.
+
+        From Blink r150201 and r150755 by <se...@chromium.org>
+
+        * fast/css/parsing-expr-error-recovery-expected.txt: Added.
+        * fast/css/parsing-expr-error-recovery.html: Added.
+
+2013-06-12  Sergio Villar Senin  <svil...@igalia.com>
+
         [css exclusions] fast/css/variables/var-inside-shape.html is failing
         https://bugs.webkit.org/show_bug.cgi?id=116059
 

Added: trunk/LayoutTests/fast/css/parsing-expr-error-recovery-expected.txt (0 => 151510)


--- trunk/LayoutTests/fast/css/parsing-expr-error-recovery-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/parsing-expr-error-recovery-expected.txt	2013-06-12 17:23:31 UTC (rev 151510)
@@ -0,0 +1,3 @@
+Tests that CSS parser correctly recovers after {}, () and [] invalid blocks.
+All tests passed
+

Added: trunk/LayoutTests/fast/css/parsing-expr-error-recovery.html (0 => 151510)


--- trunk/LayoutTests/fast/css/parsing-expr-error-recovery.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/parsing-expr-error-recovery.html	2013-06-12 17:23:31 UTC (rev 151510)
@@ -0,0 +1,33 @@
+<html>
+<body>
+<div>Tests that CSS parser correctly recovers after {}, () and [] invalid blocks.</div>
+<div id="result"></div>
+<div id="tests"></div>
+<script type="text/_javascript_">
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var BASE_EXPR = "1px,\"x\",var(y) /calc(1px + (((5px)))),-webkit-min(1px,2px)";
+var INVALID_BLOCKS = ["#", "{}", "()", "[]", "{(){{}{{}}[]}}", "(})", "(])", "[}]", "[)]", "{)}", "{]}", "#({})"];
+
+var tests = document.getElementById("tests");
+for (var i = 0; i <= BASE_EXPR.length; i++) {
+    for (var j = 0; j < INVALID_BLOCKS.length; j++) {
+        var invalidExpr = BASE_EXPR.substr(0, i) + INVALID_BLOCKS[j] + BASE_EXPR.substr(i);
+        var test = document.createElement("DIV");
+        test.textContent = "failed: " + invalidExpr;
+        test.style.cssText = "color:" + invalidExpr + "; display: none;";
+        tests.appendChild(test);
+    }
+}
+
+var failed = 0;
+for (var test = tests.firstChild; test; test = test.nextSibling) {
+   if (getComputedStyle(test).display != "none")
+       failed++;
+}
+
+document.getElementById("result").textContent = failed ? "Failed " + failed + " tests" : "All tests passed";
+
+</script>
+</body>

Modified: trunk/Source/WebCore/ChangeLog (151509 => 151510)


--- trunk/Source/WebCore/ChangeLog	2013-06-12 17:22:57 UTC (rev 151509)
+++ trunk/Source/WebCore/ChangeLog	2013-06-12 17:23:31 UTC (rev 151510)
@@ -1,3 +1,22 @@
+2013-06-12  Sergio Villar Senin  <svil...@igalia.com>
+
+        Skipping {}, () and [] blocks while error recovering in CSS
+        https://bugs.webkit.org/show_bug.cgi?id=116071
+
+        Reviewed by Darin Adler.
+
+        From Blink r150201 and r150755 by <se...@chromium.org>
+
+        Test: fast/css/parsing-expr-error-recovery.html
+
+        The CSS parser should properly recover from invalid {}, () and []
+        blocks skipping them instead of discarding the whole declaration
+        as invalid. This merge is actually made of two different changes
+        from Blink, the original one that fixes the bug and another one
+        which refactors a bit the code making it more legible.
+
+        * css/CSSGrammar.y.in:
+
 2013-06-12  Alberto Garcia  <agar...@igalia.com>
 
         [BlackBerry] Remove dead WebDOM code

Modified: trunk/Source/WebCore/css/CSSGrammar.y.in (151509 => 151510)


--- trunk/Source/WebCore/css/CSSGrammar.y.in	2013-06-12 17:22:57 UTC (rev 151509)
+++ trunk/Source/WebCore/css/CSSGrammar.y.in	2013-06-12 17:23:31 UTC (rev 151510)
@@ -321,12 +321,14 @@
 %type <character> operator
 
 %type <valueList> expr
+%type <valueList> valid_expr
 %type <value> term
 %type <value> unary_term
 %type <value> function
 %type <value> calc_func_term
 %type <character> calc_func_operator
 %type <valueList> calc_func_expr
+%type <valueList> valid_calc_func_expr
 %type <valueList> calc_func_expr_list
 %type <valueList> calc_func_paren_expr
 %type <value> calc_function
@@ -1638,11 +1640,16 @@
   ;
 
 expr:
+    valid_expr
+    | valid_expr expr_recovery { $$ = 0; }
+  ;
+
+valid_expr:
     term {
         $$ = parser->createFloatingValueList();
         $$->addValue(parser->sinkFloatingValue($1));
     }
-    | expr operator term {
+    | valid_expr operator term {
         $$ = $1;
         if ($$) {
             if ($2) {
@@ -1655,9 +1662,6 @@
             $$->addValue(parser->sinkFloatingValue($3));
         }
     }
-    | expr expr_recovery {
-        $$ = 0;
-    }
   ;
 
 expr_recovery:
@@ -1829,6 +1833,11 @@
   ;
 
 calc_func_expr:
+    valid_calc_func_expr
+    | valid_calc_func_expr expr_recovery { $$ = 0; }
+  ;
+
+valid_calc_func_expr:
     calc_func_term {
         $$ = parser->createFloatingValueList();
         $$->addValue(parser->sinkFloatingValue($1));
@@ -1859,9 +1868,6 @@
             $$ = 0;
     }
     | calc_func_paren_expr
-    | calc_func_expr error {
-        $$ = 0;
-    }
   ;
 
 calc_func_expr_list:
@@ -1959,19 +1965,26 @@
     ;
 
 invalid_block:
-    '{' error invalid_block_list error closing_brace {
+    '{' error_recovery closing_brace {
         parser->invalidBlockHit();
     }
-  | '{' error closing_brace {
-        parser->invalidBlockHit();
-    }
     ;
 
-invalid_block_list:
-    invalid_block
-  | invalid_block_list error invalid_block
-;
+invalid_square_brackets_block:
+    '[' error_recovery ']'
+  | '[' error_recovery TOKEN_EOF
+    ;
 
+invalid_parentheses_block:
+    opening_parenthesis error_recovery closing_parenthesis;
+
+opening_parenthesis:
+    '(' | FUNCTION | CALCFUNCTION | VARFUNCTION | MINFUNCTION | MAXFUNCTION | ANYFUNCTION | NOTFUNCTION
+#if ENABLE_VIDEO_TRACK
+    | CUEFUNCTION
+#endif
+    ;
+
 error_location: {
         $$ = parser->currentLocation();
     }
@@ -1979,8 +1992,10 @@
 
 error_recovery:
     /* empty */
+  | error_recovery error
   | error_recovery invalid_block
-  | error_recovery error
+  | error_recovery invalid_square_brackets_block
+  | error_recovery invalid_parentheses_block
     ;
 
 %%
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to