1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 13:17:35 +00:00

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).
This commit is contained in:
MacDue 2023-08-02 22:19:54 +01:00 committed by Andreas Kling
parent 6ea4be36b5
commit abd53a8719

View file

@ -516,14 +516,15 @@ void Tab::focus_location_editor()
m_location_edit->selectAll(); m_location_edit->selectAll();
} }
void Tab::navigate(QString url, LoadType load_type) void Tab::navigate(QString url_qstring, LoadType load_type)
{ {
if (url.startsWith("/")) auto url_string = ak_deprecated_string_from_qstring(url_qstring);
url = "file://" + url; if (url_string.starts_with('/'))
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_string = DeprecatedString::formatted("file://{}", url_string);
url = "https://" + url; else if (URL url = url_string; !url.is_valid())
url_string = DeprecatedString::formatted("https://{}", url_string);
m_is_history_navigation = (load_type == LoadType::HistoryNavigation); m_is_history_navigation = (load_type == LoadType::HistoryNavigation);
view().load(ak_deprecated_string_from_qstring(url)); view().load(url_string);
} }
void Tab::back() void Tab::back()