From d1226f0b15906d12c4b4aad0e061c1fd02c30467 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sun, 28 Jan 2024 20:07:48 +0000 Subject: [PATCH] LibWeb: Don't crash when querying offsets of empty inline elements Previously, querying `offsetTop` or `offsetLeft` of an inline element with no text would cause a crash. --- .../expected/DOM/Offset-of-empty-inline-element.txt | 2 ++ .../input/DOM/Offset-of-empty-inline-element.html | 12 ++++++++++++ Userland/Libraries/LibWeb/Painting/Paintable.cpp | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/DOM/Offset-of-empty-inline-element.txt create mode 100644 Tests/LibWeb/Text/input/DOM/Offset-of-empty-inline-element.html diff --git a/Tests/LibWeb/Text/expected/DOM/Offset-of-empty-inline-element.txt b/Tests/LibWeb/Text/expected/DOM/Offset-of-empty-inline-element.txt new file mode 100644 index 0000000000..369a7c1278 --- /dev/null +++ b/Tests/LibWeb/Text/expected/DOM/Offset-of-empty-inline-element.txt @@ -0,0 +1,2 @@ + Top: 0 +Left: 0 diff --git a/Tests/LibWeb/Text/input/DOM/Offset-of-empty-inline-element.html b/Tests/LibWeb/Text/input/DOM/Offset-of-empty-inline-element.html new file mode 100644 index 0000000000..59adbb78a4 --- /dev/null +++ b/Tests/LibWeb/Text/input/DOM/Offset-of-empty-inline-element.html @@ -0,0 +1,12 @@ + + + + + + diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.cpp b/Userland/Libraries/LibWeb/Painting/Paintable.cpp index 899b934316..61eca81b3d 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/Paintable.cpp @@ -158,7 +158,7 @@ CSSPixelPoint Paintable::box_type_agnostic_position() const auto const& inline_paintable = static_cast(*this); if (!inline_paintable.fragments().is_empty()) return inline_paintable.fragments().first().absolute_rect().location(); - VERIFY_NOT_REACHED(); + return inline_paintable.bounding_rect().location(); } CSSPixelPoint position;