From abd53a871906b532f7d42ba1d3c33422cf0da1f9 Mon Sep 17 00:00:00 2001 From: MacDue Date: Wed, 2 Aug 2023 22:19:54 +0100 Subject: [PATCH] Ladybird: Use AK::Url rather than prefix list to check if URL is valid If a URL is not valid we try navigating to https:// + the url. It's better to ask AK::Url if it thinks the url is valid than put a big list of prefixes here, with this obscure protocols like Gemini are now recognised and with `--enable-lagom-networking` can be viewed in Ladybird (thanks to #2218). --- Ladybird/Tab.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index ae146115c5..81efe69268 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -516,14 +516,15 @@ void Tab::focus_location_editor() m_location_edit->selectAll(); } -void Tab::navigate(QString url, LoadType load_type) +void Tab::navigate(QString url_qstring, LoadType load_type) { - if (url.startsWith("/")) - url = "file://" + url; - else if (!url.startsWith("http://", Qt::CaseInsensitive) && !url.startsWith("https://", Qt::CaseInsensitive) && !url.startsWith("file://", Qt::CaseInsensitive) && !url.startsWith("about:", Qt::CaseInsensitive) && !url.startsWith("data:", Qt::CaseInsensitive)) - url = "https://" + url; + auto url_string = ak_deprecated_string_from_qstring(url_qstring); + if (url_string.starts_with('/')) + url_string = DeprecatedString::formatted("file://{}", url_string); + else if (URL url = url_string; !url.is_valid()) + url_string = DeprecatedString::formatted("https://{}", url_string); m_is_history_navigation = (load_type == LoadType::HistoryNavigation); - view().load(ak_deprecated_string_from_qstring(url)); + view().load(url_string); } void Tab::back()