aboutsummaryrefslogtreecommitdiff
path: root/src/shared/urls.ts
diff options
context:
space:
mode:
authorchenchao <wenbushi@gmail.com>2019-11-07 11:14:03 +0800
committerchenchao <wenbushi@gmail.com>2019-11-07 11:14:03 +0800
commitddd3b08a4a3b393375b6e9716697b9442fcfa66d (patch)
treeaf7e201cd967a4268822f8794955d819a6eff259 /src/shared/urls.ts
parentf3ce1c300a79fab2f87c38cd853477e7756edb55 (diff)
handle localhost urls with path
Diffstat (limited to 'src/shared/urls.ts')
-rw-r--r--src/shared/urls.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/shared/urls.ts b/src/shared/urls.ts
index ab01c49..8fa9a49 100644
--- a/src/shared/urls.ts
+++ b/src/shared/urls.ts
@@ -16,6 +16,20 @@ const isLocalhost = (url: string): boolean => {
return host === 'localhost' && !isNaN(Number(port));
};
+const isMissingHttp = (keywords: string): boolean => {
+ if (keywords.includes('.') && !keywords.includes(' ')) {
+ return true;
+ }
+
+ try {
+ let u = new URL('http://' + keywords);
+ return isLocalhost(u.host)
+ } catch (e) {
+ // fallthrough
+ }
+ return false;
+};
+
const searchUrl = (keywords: string, search: Search): string => {
try {
let u = new URL(keywords);
@@ -25,10 +39,11 @@ const searchUrl = (keywords: string, search: Search): string => {
} catch (e) {
// fallthrough
}
- if (isLocalhost(keywords) ||
- (keywords.includes('.') && !keywords.includes(' '))) {
+
+ if (isMissingHttp(keywords)) {
return 'http://' + keywords;
}
+
let template = search.engines[search.defaultEngine];
let query = keywords;