From d755a83c09a5fba82a91f9cc3f9e3b2e07880127 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 11 Aug 2024 00:39:07 +1200 Subject: [PATCH] LibWeb: Actually set empty serialized query to OptionalNone Because the type returned by to_string is a String, _not_ an Optional, the following code: if (serialized_query.is_empty()) serialized_query = {}; Was achieving nothing at all! Make sure that the type is an Optional so that we're not just setting an empty string to an empty string. --- .../Text/expected/URL/search-params-with-no-query.txt | 2 ++ .../Text/input/URL/search-params-with-no-query.html | 9 +++++++++ Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp | 7 ++++--- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/URL/search-params-with-no-query.txt create mode 100644 Tests/LibWeb/Text/input/URL/search-params-with-no-query.html diff --git a/Tests/LibWeb/Text/expected/URL/search-params-with-no-query.txt b/Tests/LibWeb/Text/expected/URL/search-params-with-no-query.txt new file mode 100644 index 000000000000..1d693b47077d --- /dev/null +++ b/Tests/LibWeb/Text/expected/URL/search-params-with-no-query.txt @@ -0,0 +1,2 @@ +https://www.birdoftheyear.org.nz/? +https://www.birdoftheyear.org.nz/ diff --git a/Tests/LibWeb/Text/input/URL/search-params-with-no-query.html b/Tests/LibWeb/Text/input/URL/search-params-with-no-query.html new file mode 100644 index 000000000000..fba4c9901437 --- /dev/null +++ b/Tests/LibWeb/Text/input/URL/search-params-with-no-query.html @@ -0,0 +1,9 @@ + + diff --git a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp index f424ada69a50..2a3863eb395b 100644 --- a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp +++ b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2021, Idan Horowitz - * Copyright (c) 2023, Shannon Booth + * Copyright (c) 2023-2024, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -213,6 +213,7 @@ void URLSearchParams::append(String const& name, String const& value) update(); } +// https://url.spec.whatwg.org/#concept-urlsearchparams-update void URLSearchParams::update() { // 1. If query’s URL object is null, then return. @@ -220,10 +221,10 @@ void URLSearchParams::update() return; // 2. Let serializedQuery be the serialization of query’s list. - auto serialized_query = to_string(); + Optional serialized_query = to_string(); // 3. If serializedQuery is the empty string, then set serializedQuery to null. - if (serialized_query.is_empty()) + if (serialized_query == String {}) serialized_query = {}; // 4. Set query’s URL object’s URL’s query to serializedQuery.