Update tests and docs

This commit is contained in:
Oliver Blanthorn 2026-07-25 22:35:45 +02:00
parent 0a9e073aaf
commit 3a51611161
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
2 changed files with 8 additions and 9 deletions

View file

@ -346,18 +346,18 @@ function test_url_graft_path() {
function test_url_query_interpolation() {
let cases = [
["http://example.com/%s000", "a/query", "http://example.com/a/query000"],
["http://example.com/%s000", "a/query", "http://example.com/a%2Fquery000"],
[
// not percent-encoded and appended
// appended to the path
"http://example.com",
"a/query",
"http://example.com/a/query",
"http://example.com/a%2Fquery",
],
[
// not percent-encoded and interpolated
// interpolated into the path
"http://example.com/%s/path",
"a/query",
"http://example.com/a/query/path",
"http://example.com/a%2Fquery/path",
],
[
// percent-encoded and appended

View file

@ -439,14 +439,13 @@ export function searchUrlToArgs(
* If the URL pattern contains "%s", the query is interpolated there. If not,
* it is appended to the end of the pattern.
*
* If the interpolation point is in the query string of the URL, it is
* percent encoded, otherwise it is is inserted verbatim.
* The search item is percent encoded before it is inserted.
*
* @param urlPattern a URL to interpolate/append a query to
* @param query a query to interpolate/append into the URL
*
* @return the URL with the query encoded (if needed) and
* inserted at the relevant point
* @return the URL with the query encoded and inserted at the
* relevant point
*/
export function interpolateSearchItem(urlPattern: URL, query: string): URL {
const hasInterpolationPoint = urlPattern.href.includes("%s")