aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchenchao <wenbushi@gmail.com>2019-11-06 18:13:23 +0800
committerchenchao <wenbushi@gmail.com>2019-11-06 18:14:09 +0800
commitf3ce1c300a79fab2f87c38cd853477e7756edb55 (patch)
treec876d11ad28269144a96aeef763f725b39d9cb63 /src
parent5758100f43c72efb5d6ad15617cd6c3c7c2abfc8 (diff)
more localhost use cases
Diffstat (limited to 'src')
-rw-r--r--src/shared/urls.ts14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/shared/urls.ts b/src/shared/urls.ts
index b256b20..ab01c49 100644
--- a/src/shared/urls.ts
+++ b/src/shared/urls.ts
@@ -5,7 +5,16 @@ const trimStart = (str: string): string => {
return str.replace(/^\s+/, '');
};
-const SUPPORTED_PROTOCOLS = ['http:', 'https:', 'ftp:', 'mailto:', 'about:', 'localhost:'];
+const SUPPORTED_PROTOCOLS = ['http:', 'https:', 'ftp:', 'mailto:', 'about:'];
+
+const isLocalhost = (url: string): boolean => {
+ if (url === 'localhost') {
+ return true;
+ }
+
+ let [host, port] = url.split(':', 2);
+ return host === 'localhost' && !isNaN(Number(port));
+};
const searchUrl = (keywords: string, search: Search): string => {
try {
@@ -16,7 +25,8 @@ const searchUrl = (keywords: string, search: Search): string => {
} catch (e) {
// fallthrough
}
- if (keywords.includes('.') && !keywords.includes(' ')) {
+ if (isLocalhost(keywords) ||
+ (keywords.includes('.') && !keywords.includes(' '))) {
return 'http://' + keywords;
}
let template = search.engines[search.defaultEngine];