allow full url search templates

This commit is contained in:
cade
2024-06-13 16:49:42 -07:00
parent d45c5d1468
commit 50160383fb
+11 -11
View File
@@ -381,12 +381,12 @@
}); });
} }
static #formatSearchUrl(url, searchPath, search) { static #formatSearchUrl(commandUrl, searchTemplate, query) {
if (!searchPath) return url; if (!searchTemplate) return commandUrl;
const [baseUrl] = Search.#splitUrl(url); const [commandBase] = Search.#splitUrl(commandUrl);
const urlQuery = encodeURIComponent(search); const [searchBase, path] = Search.#splitUrl(searchTemplate);
searchPath = searchPath.replace(/{}/g, urlQuery); const base = searchBase ?? commandBase;
return baseUrl + searchPath; return `${base}${path}`.replace(/{}/g, encodeURIComponent(query));
} }
static #hasProtocol(s) { static #hasProtocol(s) {
@@ -436,11 +436,11 @@
}; };
static #splitUrl(url) { static #splitUrl(url) {
const parser = document.createElement('a'); const a = document.createElement('a');
parser.href = url; a.href = url;
const baseUrl = `${parser.protocol}//${parser.hostname}`; const baseUrl = a.hostname ? `${a.protocol}//${a.hostname}` : null;
const rest = `${parser.pathname}${parser.search}`; const rest = `${a.pathname}${a.search}`;
return [baseUrl, rest]; return [baseUrl, decodeURIComponent(rest)];
} }
#close() { #close() {