summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornetworkException <git@nwex.de>2022-02-06 16:29:49 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-07 10:52:55 +0100
commitb28e861776661f51122a39ca6e0d045833e78c94 (patch)
tree1e89174602aa6d60c413d192624e75d028bf66d7
parente7b8498a4ae3f702ace4e88c669e2bdfb69789f7 (diff)
downloadserenity-b28e861776661f51122a39ca6e0d045833e78c94.zip
Browser: Better handle ports in user input to url conversion
Previously it was hard to enter a url with a port in browser: "example.com:8080" -> Protocol not implemented: example.com This patch makes an attempt at parsing the input as an url with http first an validates if the url has a port. "example.com:8080" -> "http://example.com:8080"
-rw-r--r--Userland/Applications/Browser/Tab.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp
index 40ff08a91d..8ceea29698 100644
--- a/Userland/Applications/Browser/Tab.cpp
+++ b/Userland/Applications/Browser/Tab.cpp
@@ -38,20 +38,20 @@
namespace Browser {
-URL url_from_user_input(const String& input)
+URL url_from_user_input(String const& input)
{
- String url_string = input;
if (input.starts_with("?") && !g_search_engine.is_empty())
- url_string = g_search_engine.replace("{}", URL::percent_encode(input.substring_view(1)));
+ return URL(g_search_engine.replace("{}", URL::percent_encode(input.substring_view(1))));
- URL url = URL(url_string);
+ URL url_with_http_schema = URL(String::formatted("http://{}", input));
+ if (url_with_http_schema.is_valid() && url_with_http_schema.port().has_value())
+ return url_with_http_schema;
+
+ URL url = URL(input);
if (url.is_valid())
return url;
- StringBuilder builder;
- builder.append("http://");
- builder.append(url_string);
- return URL(builder.build());
+ return url_with_http_schema;
}
void Tab::start_download(const URL& url)