REGRESSION (r95502): Assertion failure in CSSPrimitiveValue::computeLengthDouble...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 2 Oct 2011 08:25:34 +0000 (08:25 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 2 Oct 2011 08:25:34 +0000 (08:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=68760

Reviewed by Antti Koivisto.

Source/WebCore:

Test: fast/media/invalid-lengths.html

Made length-comparison media queries accept only length values. In compatibility mode, numbers
are allowed as well, and they are interpreted as pixels.

* css/MediaQueryEvaluator.cpp:
(WebCore::computeLength): Added this helper function.
(WebCore::device_heightMediaFeatureEval): Changed to use computeLength().
(WebCore::device_widthMediaFeatureEval): Ditto.
(WebCore::heightMediaFeatureEval): Ditto.
(WebCore::widthMediaFeatureEval): Ditto.

LayoutTests:

* fast/media/invalid-lengths-expected.txt: Added.
* fast/media/invalid-lengths.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/media/invalid-lengths-expected.txt [new file with mode: 0644]
LayoutTests/fast/media/invalid-lengths.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/MediaQueryEvaluator.cpp

index b7651843cad52d311ca7b8ac373daedc7b4a99f0..3226dd12c34ba9fcbab590e2ab4c83ad1eb04502 100644 (file)
@@ -1,3 +1,13 @@
+2011-10-02  Dan Bernstein  <mitz@apple.com>
+
+        REGRESSION (r95502): Assertion failure in CSSPrimitiveValue::computeLengthDouble() when media query specifies unit-less length
+        https://bugs.webkit.org/show_bug.cgi?id=68760
+
+        Reviewed by Antti Koivisto.
+
+        * fast/media/invalid-lengths-expected.txt: Added.
+        * fast/media/invalid-lengths.html: Added.
+
 2011-10-02  Dirk Schulze  <krit@webkit.org>
 
         SVG Mask should take 'color-interpolation' into account to determine the color space of the mask image
diff --git a/LayoutTests/fast/media/invalid-lengths-expected.txt b/LayoutTests/fast/media/invalid-lengths-expected.txt
new file mode 100644 (file)
index 0000000..35c8aff
--- /dev/null
@@ -0,0 +1,7 @@
+PASS: "(min-device-width: 0)" evaluates to true.
+PASS: "(min-device-width: 1px)" evaluates to true.
+PASS: "(min-device-width: 1deg)" evaluates to false.
+PASS: "(min-device-width: 1)" evaluates to false.
+PASS: "(min-device-width: solid)" evaluates to false.
+PASS: "(min-device-width: "red")" evaluates to false.
+
diff --git a/LayoutTests/fast/media/invalid-lengths.html b/LayoutTests/fast/media/invalid-lengths.html
new file mode 100644 (file)
index 0000000..749f8ab
--- /dev/null
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<pre id="console">
+</pre>
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+  
+    function log(message)
+    {
+        document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
+    }
+  
+    function testQuery(query, expected)
+    {
+        var actual = window.styleMedia.matchMedium(query);
+        var message = (actual === expected) ? 'PASS' : 'FAIL';
+        message += ": \"" + query + "\" evaluates to " + (actual ? "true" : "false") + ".";
+        log(message);
+    }
+  
+    testQuery('(min-device-width: 0)', true);
+    testQuery('(min-device-width: 1px)', true);
+    testQuery('(min-device-width: 1deg)', false);
+    testQuery('(min-device-width: 1)', false);
+    testQuery('(min-device-width: solid)', false);
+    testQuery('(min-device-width: "red")', false);
+</script>
index 99806d2ca14fdc89a2bbe6c1af30d2c34a866908..37a3776bd3a51599fbe561a2f5c6161e98aff382 100644 (file)
@@ -1,3 +1,22 @@
+2011-10-02  Dan Bernstein  <mitz@apple.com>
+
+        REGRESSION (r95502): Assertion failure in CSSPrimitiveValue::computeLengthDouble() when media query specifies unit-less length
+        https://bugs.webkit.org/show_bug.cgi?id=68760
+
+        Reviewed by Antti Koivisto.
+
+        Test: fast/media/invalid-lengths.html
+
+        Made length-comparison media queries accept only length values. In compatibility mode, numbers
+        are allowed as well, and they are interpreted as pixels.
+
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::computeLength): Added this helper function.
+        (WebCore::device_heightMediaFeatureEval): Changed to use computeLength().
+        (WebCore::device_widthMediaFeatureEval): Ditto.
+        (WebCore::heightMediaFeatureEval): Ditto.
+        (WebCore::widthMediaFeatureEval): Ditto.
+
 2011-10-02  Dirk Schulze  <krit@webkit.org>
 
         SVG Mask should take 'color-interpolation' into account to determine the color space of the mask image
index 28fc36f2a81dc35363b33a0a4e7ac8765a400317..64d4933926e4d3d3b7502c72bba23ae16891cacd 100644 (file)
@@ -306,12 +306,33 @@ static bool gridMediaFeatureEval(CSSValue* value, RenderStyle*, Frame*, MediaFea
     return false;
 }
 
+static bool computeLength(CSSValue* value, bool strict, RenderStyle* style, RenderStyle* rootStyle, int& result)
+{
+    if (!value->isPrimitiveValue())
+        return false;
+
+    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
+
+    if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_NUMBER) {
+        result = primitiveValue->getIntValue();
+        return !strict || !result;
+    }
+
+    if (primitiveValue->isLength()) {
+        result = primitiveValue->computeLength<int>(style, rootStyle);
+        return true;
+    }
+
+    return false;
+}
+
 static bool device_heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* frame, MediaFeaturePrefix op)
 {
     if (value) {
         FloatRect sg = screenRect(frame->page()->mainFrame()->view());
         RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
-        return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.height()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
+        int length;
+        return computeLength(value, !frame->document()->inQuirksMode(), style, rootStyle, length) && compareValue(static_cast<int>(sg.height()), length, op);
     }
     // ({,min-,max-}device-height)
     // assume if we have a device, assume non-zero
@@ -323,7 +344,8 @@ static bool device_widthMediaFeatureEval(CSSValue* value, RenderStyle* style, Fr
     if (value) {
         FloatRect sg = screenRect(frame->page()->mainFrame()->view());
         RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
-        return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.width()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
+        int length;
+        return computeLength(value, !frame->document()->inQuirksMode(), style, rootStyle, length) && compareValue(static_cast<int>(sg.width()), length, op);
     }
     // ({,min-,max-}device-width)
     // assume if we have a device, assume non-zero
@@ -333,10 +355,12 @@ static bool device_widthMediaFeatureEval(CSSValue* value, RenderStyle* style, Fr
 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* frame, MediaFeaturePrefix op)
 {
     FrameView* view = frame->view();
-    RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
 
-    if (value)
-        return value->isPrimitiveValue() && compareValue(view->layoutHeight(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
+    if (value) {
+        RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
+        int length;
+        return computeLength(value, !frame->document()->inQuirksMode(), style, rootStyle, length) && compareValue(view->layoutHeight(), length, op);
+    }
 
     return view->layoutHeight() != 0;
 }
@@ -344,10 +368,12 @@ static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* f
 static bool widthMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* frame, MediaFeaturePrefix op)
 {
     FrameView* view = frame->view();
-    RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
 
-    if (value)
-        return value->isPrimitiveValue() && compareValue(view->layoutWidth(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
+    if (value) {
+        RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
+        int length;
+        return computeLength(value, !frame->document()->inQuirksMode(), style, rootStyle, length) && compareValue(view->layoutWidth(), length, op);
+    }
 
     return view->layoutWidth() != 0;
 }