Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibURL+LibWeb+UI: Remove the implicit URL constructors #3668

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
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.
  • Loading branch information
shannonbooth committed Feb 22, 2025
commit cbf0ac839a79955084bc1d7ea3505aeb1f4ae835
13 changes: 1 addition & 12 deletions Libraries/LibURL/URL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2018-2020, Andreas Kling <[email protected]>
* Copyright (c) 2021, Max Wipfli <[email protected]>
* Copyright (c) 2024, Sam Atkins <[email protected]>
* Copyright (c) 2023-2025, Shannon Booth <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
Expand All @@ -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> URL::complete_url(StringView relative_url) const
{
if (!is_valid())
Expand Down
11 changes: 1 addition & 10 deletions Libraries/LibURL/URL.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <[email protected]>
* Copyright (c) 2021, Max Wipfli <[email protected]>
* Copyright (c) 2023-2024, Shannon Booth <[email protected]>
* Copyright (c) 2023-2025, Shannon Booth <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
Expand Down Expand Up @@ -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; }

Expand Down
Loading