From de89f5af6d0534af2a3b029cb0aac549b9fe8692 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 22 Feb 2025 21:52:44 +1300 Subject: [PATCH] LibURL: Remove the implicit URL constructors All URLs are now either constucted through the URL Parser or by default constructing a URL, and setting each of the fields of that URL manually. This makes it much more difficult to create invalid URLs. --- Libraries/LibURL/URL.cpp | 13 +------------ Libraries/LibURL/URL.h | 11 +---------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/Libraries/LibURL/URL.cpp b/Libraries/LibURL/URL.cpp index fea438d9a13..ccca2456817 100644 --- a/Libraries/LibURL/URL.cpp +++ b/Libraries/LibURL/URL.cpp @@ -2,6 +2,7 @@ * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Max Wipfli * Copyright (c) 2024, Sam Atkins + * Copyright (c) 2023-2025, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -21,18 +22,6 @@ namespace URL { -// FIXME: It could make sense to force users of URL to use URL::Parser::basic_parse() explicitly instead of using a constructor. -URL::URL(StringView string) - : URL(Parser::basic_parse(string).value_or(URL {})) -{ - if constexpr (URL_PARSER_DEBUG) { - if (m_data->valid) - dbgln("URL constructor: Parsed URL to be '{}'.", serialize()); - else - dbgln("URL constructor: Parsed URL to be invalid."); - } -} - Optional URL::complete_url(StringView relative_url) const { if (!is_valid()) diff --git a/Libraries/LibURL/URL.h b/Libraries/LibURL/URL.h index 5d54f6687da..4df425b4983 100644 --- a/Libraries/LibURL/URL.h +++ b/Libraries/LibURL/URL.h @@ -1,7 +1,7 @@ /* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Max Wipfli - * Copyright (c) 2023-2024, Shannon Booth + * Copyright (c) 2023-2025, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -77,15 +77,6 @@ class URL { public: URL() = default; - URL(StringView); - URL(ByteString const& string) - : URL(string.view()) - { - } - URL(String const& string) - : URL(string.bytes_as_string_view()) - { - } bool is_valid() const { return m_data->valid; }