mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 10:01:39 -05:00
parent
fe7948c0d0
commit
7a2889dd6c
1 changed files with 13 additions and 1 deletions
|
@ -354,6 +354,8 @@ export function graftUrlPath(url: URL, newTail: string, level: number) {
|
||||||
export function interpolateSearchItem(urlPattern: URL, query: string): URL {
|
export function interpolateSearchItem(urlPattern: URL, query: string): URL {
|
||||||
const hasInterpolationPoint = urlPattern.href.includes("%s")
|
const hasInterpolationPoint = urlPattern.href.includes("%s")
|
||||||
|
|
||||||
|
let queryWords = query.split(" ")
|
||||||
|
|
||||||
// percent-encode if theres a %s in the query string, or if we're apppending
|
// percent-encode if theres a %s in the query string, or if we're apppending
|
||||||
// and there's a query string
|
// and there's a query string
|
||||||
if (
|
if (
|
||||||
|
@ -361,11 +363,21 @@ export function interpolateSearchItem(urlPattern: URL, query: string): URL {
|
||||||
urlPattern.search !== ""
|
urlPattern.search !== ""
|
||||||
) {
|
) {
|
||||||
query = encodeURIComponent(query)
|
query = encodeURIComponent(query)
|
||||||
|
queryWords = queryWords.map(w => encodeURIComponent(w))
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace or append as needed
|
// replace or append as needed
|
||||||
if (hasInterpolationPoint) {
|
if (hasInterpolationPoint) {
|
||||||
return new URL(urlPattern.href.replace("%s", query))
|
let resultingURL = new URL (urlPattern.href.replace(/%s\d+/g, function(x) {
|
||||||
|
const index = parseInt(x.slice(2)) - 1
|
||||||
|
if (index >= queryWords.length) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryWords[index]
|
||||||
|
}))
|
||||||
|
|
||||||
|
return new URL(resultingURL.href.replace("%s", query))
|
||||||
} else {
|
} else {
|
||||||
return new URL(urlPattern.href + query)
|
return new URL(urlPattern.href + query)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue