aboutsummaryrefslogtreecommitdiff
path: root/src/shared/urls.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/urls.js')
-rw-r--r--src/shared/urls.js22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/shared/urls.js b/src/shared/urls.js
index d6c31e6..f7e917d 100644
--- a/src/shared/urls.js
+++ b/src/shared/urls.js
@@ -3,9 +3,9 @@ const trimStart = (str) => {
return str.replace(/^\s+/, '');
};
-const SUPPORTED_PROTOCOLS = ['http:', 'https:', 'ftp:', 'mailto:'];
+const SUPPORTED_PROTOCOLS = ['http:', 'https:', 'ftp:', 'mailto:', 'about:'];
-const normalizeUrl = (keywords, searchSettings) => {
+const searchUrl = (keywords, searchSettings) => {
try {
let u = new URL(keywords);
if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) {
@@ -28,4 +28,20 @@ const normalizeUrl = (keywords, searchSettings) => {
return template.replace('{}', encodeURIComponent(query));
};
-export { normalizeUrl };
+const normalizeUrl = (url) => {
+ try {
+ let u = new URL(url);
+ if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) {
+ return u.href;
+ }
+ } catch (e) {
+ // fallthrough
+ }
+ return 'http://' + url;
+};
+
+const homepageUrls = (value) => {
+ return value.split('|').map(normalizeUrl);
+};
+
+export { searchUrl, normalizeUrl, homepageUrls };