Просмотр исходного кода

LibWeb: Don't crash when encountering calc() inside a CSS rect() value

This allows us to run the WPT tests under quirks/unitless-length/
without crashing, giving us over 4600 new passing subtests. :^)
Andreas Kling 10 месяцев назад
Родитель
Сommit
5df6c6eecf

+ 10 - 0
Tests/LibWeb/Layout/expected/css-rect-value-with-calc-dont-crash.txt

@@ -0,0 +1,10 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+  BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
+    BlockContainer <body> at (8,8) content-size 784x0 children: not-inline
+      BlockContainer <div> at (8,8) content-size 784x0 children: inline
+        TextNode <#text>
+
+ViewportPaintable (Viewport<#document>) [0,0 800x600]
+  PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
+    PaintableWithLines (BlockContainer<BODY>) [8,8 784x0]
+      PaintableWithLines (BlockContainer<DIV>) [8,8 784x0]

+ 6 - 0
Tests/LibWeb/Layout/input/css-rect-value-with-calc-dont-crash.html

@@ -0,0 +1,6 @@
+<style>
+div {
+    clip: rect(0, 0, 0, calc(2px));
+}
+</style>
+<div>

+ 4 - 1
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -2710,7 +2710,10 @@ RefPtr<CSSStyleValue> Parser::parse_rect_value(TokenStream<ComponentValue>& toke
             auto maybe_length = parse_length(argument_tokens);
             if (!maybe_length.has_value())
                 return nullptr;
-            // FIXME: Support calculated lengths
+            if (maybe_length.value().is_calculated()) {
+                dbgln("FIXME: Support calculated lengths in rect(): {}", maybe_length.value().calculated()->to_string());
+                return nullptr;
+            }
             params.append(maybe_length.value().value());
         }
         argument_tokens.skip_whitespace();