Title: [160779] trunk
Revision
160779
Author
[email protected]
Date
2013-12-18 10:59:06 -0800 (Wed, 18 Dec 2013)

Log Message

REGRESSION (r155536): Broken error recovery in @media at-rule
https://bugs.webkit.org/show_bug.cgi?id=125637

Patch by Martin Hodovan <[email protected]> on 2013-12-18
Reviewed by Darin Adler.

Source/WebCore:

Error recovery in @media is broken if any of its rules misses the opening '{'.
The problem is that when the parser recognises the mistake it removes only the last
WHITESPACE token instead of the whole selector and tries to recover the selector again.
it swallows everything until it finds the next opening bracket. thats why the '}' brackets
of both subrules and even the @media rule are ignored, and the whole @media will be
considered invalid. By joining the selector and its trailing whitespace the error recovery
ignores the bad selector only and keep the @media rule.

Test: fast/css/media-error-recovery.html

* css/CSSGrammar.y.in:

LayoutTests:

Test with broken @media rule.

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

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (160778 => 160779)


--- trunk/LayoutTests/ChangeLog	2013-12-18 18:50:47 UTC (rev 160778)
+++ trunk/LayoutTests/ChangeLog	2013-12-18 18:59:06 UTC (rev 160779)
@@ -1,3 +1,15 @@
+2013-12-18  Martin Hodovan  <[email protected]>
+
+        REGRESSION (r155536): Broken error recovery in @media at-rule
+        https://bugs.webkit.org/show_bug.cgi?id=125637
+
+        Reviewed by Darin Adler.
+
+        Test with broken @media rule.
+
+        * fast/css/media-error-recovery-expected.txt: Added.
+        * fast/css/media-error-recovery.html: Added.
+
 2013-12-18  Chris Fleizach  <[email protected]>
 
         AX: WebKit not sending AXMenuClosed notification

Added: trunk/LayoutTests/fast/css/media-error-recovery-expected.txt (0 => 160779)


--- trunk/LayoutTests/fast/css/media-error-recovery-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/media-error-recovery-expected.txt	2013-12-18 18:59:06 UTC (rev 160779)
@@ -0,0 +1,2 @@
+Background should be green.
+SUCCESS

Added: trunk/LayoutTests/fast/css/media-error-recovery.html (0 => 160779)


--- trunk/LayoutTests/fast/css/media-error-recovery.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/media-error-recovery.html	2013-12-18 18:59:06 UTC (rev 160779)
@@ -0,0 +1,29 @@
+<html>
+<head>
+
+<script>
+    function runTest() {
+		if (window.testRunner)
+	    	    testRunner.dumpAsText();
+
+		var element = document.getElementById("styled");
+		var computedColor = window.getComputedStyle(element).backgroundColor;
+
+		if (computedColor === "rgb(0, 128, 0)")
+		    document.getElementById("result").textContent = "SUCCESS";
+		else
+		    document.getElementById("result").textContent = "FAILURE " + computedColor;
+    }
+</script>
+
+<style>
+	@media {
+		body { background-color: green; }
+		.foo background-color: red; }
+	}
+</style>		
+</head>
+<body _onload_="runTest();" id="styled">
+	<div>Background should be green.</div>
+	<div id="result"></div>
+</body>

Modified: trunk/Source/WebCore/ChangeLog (160778 => 160779)


--- trunk/Source/WebCore/ChangeLog	2013-12-18 18:50:47 UTC (rev 160778)
+++ trunk/Source/WebCore/ChangeLog	2013-12-18 18:59:06 UTC (rev 160779)
@@ -1,3 +1,22 @@
+2013-12-18  Martin Hodovan  <[email protected]>
+
+        REGRESSION (r155536): Broken error recovery in @media at-rule
+        https://bugs.webkit.org/show_bug.cgi?id=125637
+
+        Reviewed by Darin Adler.
+
+        Error recovery in @media is broken if any of its rules misses the opening '{'.
+        The problem is that when the parser recognises the mistake it removes only the last
+        WHITESPACE token instead of the whole selector and tries to recover the selector again.
+        it swallows everything until it finds the next opening bracket. thats why the '}' brackets
+        of both subrules and even the @media rule are ignored, and the whole @media will be
+        considered invalid. By joining the selector and its trailing whitespace the error recovery
+        ignores the bad selector only and keep the @media rule.
+
+        Test: fast/css/media-error-recovery.html
+
+        * css/CSSGrammar.y.in:
+
 2013-12-18  Chris Fleizach  <[email protected]>
 
         AX: WebKit not sending AXMenuClosed notification

Modified: trunk/Source/WebCore/css/CSSGrammar.y.in (160778 => 160779)


--- trunk/Source/WebCore/css/CSSGrammar.y.in	2013-12-18 18:50:47 UTC (rev 160778)
+++ trunk/Source/WebCore/css/CSSGrammar.y.in	2013-12-18 18:59:06 UTC (rev 160779)
@@ -239,8 +239,8 @@
 %type <id> property
 
 %union { CSSParserSelector* selector; }
-%type <selector> attrib class page_selector pseudo pseudo_page selector simple_selector specifier specifier_list
-%destructor { delete $$; } attrib class page_selector pseudo pseudo_page selector simple_selector specifier specifier_list
+%type <selector> attrib class page_selector pseudo pseudo_page selector selector_with_trailing_whitespace simple_selector specifier specifier_list
+%destructor { delete $$; } attrib class page_selector pseudo pseudo_page selector selector_with_trailing_whitespace simple_selector specifier specifier_list
 
 %union { Vector<OwnPtr<CSSParserSelector>>* selectorList; }
 %type <selectorList> selector_list simple_selector_list
@@ -1040,12 +1040,15 @@
     }
    ;
 
+selector_with_trailing_whitespace:
+    selector WHITESPACE;
+
 selector:
     simple_selector
-    | selector WHITESPACE
-    | selector WHITESPACE simple_selector {
+    | selector_with_trailing_whitespace
+    | selector_with_trailing_whitespace simple_selector {
         OwnPtr<CSSParserSelector> left = adoptPtr($1);
-        OwnPtr<CSSParserSelector> right = adoptPtr($3);
+        OwnPtr<CSSParserSelector> right = adoptPtr($2);
         $$ = nullptr;
         if (left && right) {
             right->appendTagHistory(CSSSelector::Descendant, left.release());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to