From 59ba2fb2ee5a75e98623b9c0f47e51442285f98c Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Sat, 1 Feb 2025 15:47:02 +1100 Subject: [PATCH] LibWeb: Clear stylesheet pointer when disabling link element This fixes a crash when enabling an already disabled link element. Fixes a crash when changing mdbook themes. --- Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 4 +++- Tests/LibWeb/Text/expected/link-re-enable-crash.txt | 1 + Tests/LibWeb/Text/input/link-re-enable-crash.html | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/link-re-enable-crash.txt create mode 100644 Tests/LibWeb/Text/input/link-re-enable-crash.html diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index ae0826c1fcf..00305f87a12 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -166,8 +166,10 @@ void HTMLLinkElement::attribute_changed(FlyString const& name, Optional m_explicitly_enabled = true; if (m_relationship & Relationship::Stylesheet) { - if (name == HTML::AttributeNames::disabled && m_loaded_style_sheet) + if (name == HTML::AttributeNames::disabled && m_loaded_style_sheet) { document_or_shadow_root_style_sheets().remove_a_css_style_sheet(*m_loaded_style_sheet); + m_loaded_style_sheet = nullptr; + } // https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:fetch-and-process-the-linked-resource // The appropriate times to fetch and process this type of link are: diff --git a/Tests/LibWeb/Text/expected/link-re-enable-crash.txt b/Tests/LibWeb/Text/expected/link-re-enable-crash.txt new file mode 100644 index 00000000000..aaecaf93c4a --- /dev/null +++ b/Tests/LibWeb/Text/expected/link-re-enable-crash.txt @@ -0,0 +1 @@ +PASS (didn't crash) diff --git a/Tests/LibWeb/Text/input/link-re-enable-crash.html b/Tests/LibWeb/Text/input/link-re-enable-crash.html new file mode 100644 index 00000000000..da98530924a --- /dev/null +++ b/Tests/LibWeb/Text/input/link-re-enable-crash.html @@ -0,0 +1,13 @@ + + + +