From 943ec820fc52ea82f64654c1fe7e21d6e08e6e63 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 11 Dec 2024 12:04:02 -0500 Subject: [PATCH] LibWeb: Avoid dereferencing an empty optional URL Here, "null" means the empty optional. We don't need to also check if the URL is valid; the url will be null if it was originally invalid. --- Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp | 2 +- Tests/LibWeb/Text/expected/HTML/href-invalid.txt | 1 + Tests/LibWeb/Text/input/HTML/href-invalid.html | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/HTML/href-invalid.txt create mode 100644 Tests/LibWeb/Text/input/HTML/href-invalid.html diff --git a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp b/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp index eb0698d2bfe..6f49f0fb6d1 100644 --- a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp +++ b/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp @@ -427,7 +427,7 @@ String HTMLHyperlinkElementUtils::href() const return String {}; // 4. Otherwise, if url is null, return this element's href content attribute's value. - if (!url->is_valid()) + if (!url.has_value()) return href_content_attribute.release_value(); // 5. Return url, serialized. diff --git a/Tests/LibWeb/Text/expected/HTML/href-invalid.txt b/Tests/LibWeb/Text/expected/HTML/href-invalid.txt new file mode 100644 index 00000000000..383281360f5 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/href-invalid.txt @@ -0,0 +1 @@ +href="http://foo:b/c" diff --git a/Tests/LibWeb/Text/input/HTML/href-invalid.html b/Tests/LibWeb/Text/input/HTML/href-invalid.html new file mode 100644 index 00000000000..b4ec10d0feb --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/href-invalid.html @@ -0,0 +1,8 @@ + +