Title: [139316] trunk
Revision
139316
Author
apav...@chromium.org
Date
2013-01-10 06:40:53 -0800 (Thu, 10 Jan 2013)

Log Message

CSSParser does not allow the absence of whitespace between "and" and "_expression_"
https://bugs.webkit.org/show_bug.cgi?id=106458

Reviewed by Antti Koivisto.

Source/WebCore:

The issue was that a construct similar to "and(max-width: 480px)" looks like a function call (token type FUNCTION), even though
it is actually a MEDIA_AND followed by a parenthesized _expression_.

Test: fast/css/media-rule-no-whitespace.html

* css/CSSParser.cpp:
(WebCore::CSSParser::detectFunctionTypeToken): Return if the detection has been successful.
(WebCore::CSSParser::realLex): Test for media query tokens if function type detection has failed.
* css/CSSParser.h:

LayoutTests:

* fast/css/media-rule-no-whitespace-expected.txt: Added.
* fast/css/media-rule-no-whitespace.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (139315 => 139316)


--- trunk/LayoutTests/ChangeLog	2013-01-10 14:23:58 UTC (rev 139315)
+++ trunk/LayoutTests/ChangeLog	2013-01-10 14:40:53 UTC (rev 139316)
@@ -1,3 +1,13 @@
+2013-01-10  Alexander Pavlov  <apav...@chromium.org>
+
+        CSSParser does not allow the absence of whitespace between "and" and "_expression_"
+        https://bugs.webkit.org/show_bug.cgi?id=106458
+
+        Reviewed by Antti Koivisto.
+
+        * fast/css/media-rule-no-whitespace-expected.txt: Added.
+        * fast/css/media-rule-no-whitespace.html: Added.
+
 2013-01-10  Florin Malita  <fmal...@chromium.org>
 
         [Chromium] Unreviewed gardening.

Added: trunk/LayoutTests/fast/css/media-rule-no-whitespace-expected.txt (0 => 139316)


--- trunk/LayoutTests/fast/css/media-rule-no-whitespace-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/media-rule-no-whitespace-expected.txt	2013-01-10 14:40:53 UTC (rev 139316)
@@ -0,0 +1,2 @@
+This should be green
+SUCCESS

Added: trunk/LayoutTests/fast/css/media-rule-no-whitespace.html (0 => 139316)


--- trunk/LayoutTests/fast/css/media-rule-no-whitespace.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/media-rule-no-whitespace.html	2013-01-10 14:40:53 UTC (rev 139316)
@@ -0,0 +1,25 @@
+<html>
+    <head>
+        <style>
+            @media all and(min-width: 2px) { #styled { color: green; } }
+            @media all and(max-width: 1px) { #styled { color: red; } }
+        </style>
+        <script>
+            function runTest() {
+                if (window.testRunner)
+                    testRunner.dumpAsText();
+
+                var element = document.getElementById('styled');
+                var computedColor = window.getComputedStyle(element).color;
+                if (computedColor === "rgb(0, 128, 0)")
+                    document.getElementById("result").textContent = "SUCCESS";
+                else
+                    document.getElementById("result").textContent = "FAILURE: " + computedColor;
+            }
+        </script>
+    </head>
+    <body _onload_="runTest();">
+        <div id="styled">This should be green</div>
+        <div id="result">FAILURE</div>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (139315 => 139316)


--- trunk/Source/WebCore/ChangeLog	2013-01-10 14:23:58 UTC (rev 139315)
+++ trunk/Source/WebCore/ChangeLog	2013-01-10 14:40:53 UTC (rev 139316)
@@ -1,3 +1,20 @@
+2013-01-10  Alexander Pavlov  <apav...@chromium.org>
+
+        CSSParser does not allow the absence of whitespace between "and" and "_expression_"
+        https://bugs.webkit.org/show_bug.cgi?id=106458
+
+        Reviewed by Antti Koivisto.
+
+        The issue was that a construct similar to "and(max-width: 480px)" looks like a function call (token type FUNCTION), even though
+        it is actually a MEDIA_AND followed by a parenthesized _expression_.
+
+        Test: fast/css/media-rule-no-whitespace.html
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::detectFunctionTypeToken): Return if the detection has been successful.
+        (WebCore::CSSParser::realLex): Test for media query tokens if function type detection has failed.
+        * css/CSSParser.h:
+
 2013-01-10  Alexis Menard  <ale...@webkit.org>
 
         ASSERT_NOT_REACHED in StylePropertySet::fontValue when accessing font style property through JS after setting style font size.

Modified: trunk/Source/WebCore/css/CSSParser.cpp (139315 => 139316)


--- trunk/Source/WebCore/css/CSSParser.cpp	2013-01-10 14:23:58 UTC (rev 139315)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2013-01-10 14:40:53 UTC (rev 139316)
@@ -9479,43 +9479,59 @@
 }
 
 template <typename CharacterType>
-inline void CSSParser::detectFunctionTypeToken(int length)
+inline bool CSSParser::detectFunctionTypeToken(int length)
 {
     ASSERT(length > 0);
     CharacterType* name = tokenStart<CharacterType>();
 
     switch (length) {
     case 3:
-        if (isASCIIAlphaCaselessEqual(name[0], 'n') && isASCIIAlphaCaselessEqual(name[1], 'o') && isASCIIAlphaCaselessEqual(name[2], 't'))
+        if (isASCIIAlphaCaselessEqual(name[0], 'n') && isASCIIAlphaCaselessEqual(name[1], 'o') && isASCIIAlphaCaselessEqual(name[2], 't')) {
             m_token = NOTFUNCTION;
-        else if (isASCIIAlphaCaselessEqual(name[0], 'u') && isASCIIAlphaCaselessEqual(name[1], 'r') && isASCIIAlphaCaselessEqual(name[2], 'l'))
+            return true;
+        }
+        if (isASCIIAlphaCaselessEqual(name[0], 'u') && isASCIIAlphaCaselessEqual(name[1], 'r') && isASCIIAlphaCaselessEqual(name[2], 'l')) {
             m_token = URI;
+            return true;
+        }
 #if ENABLE(VIDEO_TRACK)
-        else if (isASCIIAlphaCaselessEqual(name[0], 'c') && isASCIIAlphaCaselessEqual(name[1], 'u') && isASCIIAlphaCaselessEqual(name[2], 'e'))
+        if (isASCIIAlphaCaselessEqual(name[0], 'c') && isASCIIAlphaCaselessEqual(name[1], 'u') && isASCIIAlphaCaselessEqual(name[2], 'e')) {
             m_token = CUEFUNCTION;
+            return true;
+        }
 #endif
-        return;
+        return false;
 
     case 9:
-        if (isEqualToCSSIdentifier(name, "nth-child"))
+        if (isEqualToCSSIdentifier(name, "nth-child")) {
             m_parsingMode = NthChildMode;
-        return;
+            return true;
+        }
+        return false;
 
     case 11:
-        if (isEqualToCSSIdentifier(name, "nth-of-type"))
+        if (isEqualToCSSIdentifier(name, "nth-of-type")) {
             m_parsingMode = NthChildMode;
-        return;
+            return true;
+        }
+        return false;
 
     case 14:
-        if (isEqualToCSSIdentifier(name, "nth-last-child"))
+        if (isEqualToCSSIdentifier(name, "nth-last-child")) {
             m_parsingMode = NthChildMode;
-        return;
+            return true;
+        }
+        return false;
 
     case 16:
-        if (isEqualToCSSIdentifier(name, "nth-last-of-type"))
+        if (isEqualToCSSIdentifier(name, "nth-last-of-type")) {
             m_parsingMode = NthChildMode;
-        return;
+            return true;
+        }
+        return false;
     }
+
+    return false;
 }
 
 template <typename CharacterType>
@@ -9950,14 +9966,24 @@
                     break;
             }
 #endif
-
             m_token = FUNCTION;
-            if (!hasEscape)
-                detectFunctionTypeToken<SrcCharacterType>(result - tokenStart<SrcCharacterType>());
-            ++currentCharacter<SrcCharacterType>();
-            ++result;
-            ++yylval->string.m_length;
+            bool shouldSkipParenthesis = true;
+            if (!hasEscape) {
+                bool detected = detectFunctionTypeToken<SrcCharacterType>(result - tokenStart<SrcCharacterType>());
+                if (!detected && m_parsingMode == MediaQueryMode) {
+                    // ... and(max-width: 480px) ... looks like a function, but in fact it is not,
+                    // so run more detection code in the MediaQueryMode.
+                    detectMediaQueryToken<SrcCharacterType>(result - tokenStart<SrcCharacterType>());
+                    shouldSkipParenthesis = false;
+                }
+            }
 
+            if (LIKELY(shouldSkipParenthesis)) {
+                ++currentCharacter<SrcCharacterType>();
+                ++result;
+                ++yylval->string.m_length;
+            }
+
             if (token() == URI) {
                 m_token = FUNCTION;
                 // Check whether it is really an URI.

Modified: trunk/Source/WebCore/css/CSSParser.h (139315 => 139316)


--- trunk/Source/WebCore/css/CSSParser.h	2013-01-10 14:23:58 UTC (rev 139315)
+++ trunk/Source/WebCore/css/CSSParser.h	2013-01-10 14:40:53 UTC (rev 139316)
@@ -445,7 +445,7 @@
     template <typename CharacterType>
     bool parseNthChildExtra();
     template <typename CharacterType>
-    inline void detectFunctionTypeToken(int);
+    inline bool detectFunctionTypeToken(int);
     template <typename CharacterType>
     inline void detectMediaQueryToken(int);
     template <typename CharacterType>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to