mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibWebView: Don't add '.com' to valid TLD when Ctrl is pressed
If Ctrl is pressed when a string is entered into the location bar and that string doesn't contain a valid TLD, ".com" is added to that string. Previously, only a small, fixed set of TLDs was checked. We now use the public suffix list to determine if the given address contains a valid TLD.
This commit is contained in:
parent
9f75e26385
commit
c3680a02a7
Notes:
github-actions[bot]
2025-01-26 13:28:21 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/c3680a02a73 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3326 Reviewed-by: https://github.com/gmta ✅
1 changed files with 10 additions and 10 deletions
|
@ -28,21 +28,21 @@ Optional<URL::URL> sanitize_url(StringView url, Optional<StringView> search_engi
|
|||
return MUST(String::formatted(*search_engine, URL::percent_decode(url)));
|
||||
};
|
||||
|
||||
String url_buffer;
|
||||
|
||||
if (append_tld == AppendTLD::Yes) {
|
||||
// FIXME: Expand the list of top level domains.
|
||||
if (!url.ends_with(".com"sv) && !url.ends_with(".net"sv) && !url.ends_with(".org"sv)) {
|
||||
url_buffer = MUST(String::formatted("{}.com", url));
|
||||
url = url_buffer;
|
||||
}
|
||||
}
|
||||
|
||||
ByteString url_with_scheme = url;
|
||||
if (!(url_with_scheme.starts_with("about:"sv) || url_with_scheme.contains("://"sv) || url_with_scheme.starts_with("data:"sv)))
|
||||
url_with_scheme = ByteString::formatted("https://{}"sv, url_with_scheme);
|
||||
|
||||
auto result = URL::create_with_url_or_path(url_with_scheme);
|
||||
|
||||
if (result.is_valid() && append_tld == AppendTLD::Yes) {
|
||||
if (auto maybe_host = result.host(); maybe_host.has_value()) {
|
||||
auto serialized_host = maybe_host->serialize();
|
||||
auto maybe_public_suffix = URL::get_public_suffix(serialized_host);
|
||||
if (!maybe_public_suffix.has_value() || *maybe_public_suffix == serialized_host)
|
||||
result.set_host(MUST(String::formatted("{}.com", serialized_host)));
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.is_valid())
|
||||
return format_search_engine();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue