Everywhere: Remove some use of the URL constructors

These make it too easy to construct an invalid URL, which makes it
difficult to remove the valid state of URL - which this API relies
on.
This commit is contained in:
Shannon Booth 2025-02-16 14:45:52 +13:00 committed by Tim Flynn
commit d62cf0a807
Notes: github-actions[bot] 2025-02-19 13:02:46 +00:00
11 changed files with 341 additions and 329 deletions

View file

@ -6,6 +6,7 @@
#include <AK/String.h>
#include <LibURL/Origin.h>
#include <LibURL/Parser.h>
#include <LibURL/URL.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOMURL/DOMURL.h>
@ -73,16 +74,16 @@ ErrorOr<void> AutoplayAllowlist::enable_for_origins(ReadonlySpan<String> origins
TRY(allowlist.try_ensure_capacity(origins.size()));
for (auto const& origin : origins) {
URL::URL url { origin };
auto url = URL::Parser::basic_parse(origin);
if (!url.is_valid())
url = TRY(String::formatted("https://{}", origin));
if (!url.is_valid()) {
if (!url.has_value())
url = URL::Parser::basic_parse(TRY(String::formatted("https://{}", origin)));
if (!url.has_value()) {
dbgln("Invalid origin for autoplay allowlist: {}", origin);
continue;
}
TRY(allowlist.try_append(url.origin()));
TRY(allowlist.try_append(url->origin()));
}
return {};