From 56441fe3e61ae42ffe4379a9480411342bab3e2c Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Mon, 4 Nov 2024 09:28:27 +0000 Subject: [PATCH] LibWeb: Don't crash when input with no associated text node loses focus --- .../Text/expected/HTML/HTMLInputElement-blur.txt | 1 + .../LibWeb/Text/input/HTML/HTMLInputElement-blur.html | 11 +++++++++++ Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 7 ++++--- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/HTML/HTMLInputElement-blur.txt create mode 100644 Tests/LibWeb/Text/input/HTML/HTMLInputElement-blur.html diff --git a/Tests/LibWeb/Text/expected/HTML/HTMLInputElement-blur.txt b/Tests/LibWeb/Text/expected/HTML/HTMLInputElement-blur.txt new file mode 100644 index 0000000000..aaecaf93c4 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/HTMLInputElement-blur.txt @@ -0,0 +1 @@ +PASS (didn't crash) diff --git a/Tests/LibWeb/Text/input/HTML/HTMLInputElement-blur.html b/Tests/LibWeb/Text/input/HTML/HTMLInputElement-blur.html new file mode 100644 index 0000000000..cb1aec6bec --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/HTMLInputElement-blur.html @@ -0,0 +1,11 @@ + + + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 0c2c957df8..d14771f584 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1187,11 +1187,12 @@ void HTMLInputElement::did_receive_focus() void HTMLInputElement::did_lose_focus() { - if (m_text_node) + if (m_text_node) { m_text_node->invalidate_style(DOM::StyleInvalidationReason::DidLoseFocus); - if (auto* paintable = m_text_node->paintable()) - paintable->set_selected(false); + if (auto* paintable = m_text_node->paintable()) + paintable->set_selected(false); + } if (m_placeholder_text_node) m_placeholder_text_node->invalidate_style(DOM::StyleInvalidationReason::DidLoseFocus);