diff options
Diffstat (limited to 'lib/internal/url.js')
-rw-r--r-- | lib/internal/url.js | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/lib/internal/url.js b/lib/internal/url.js index 441a02f045..ccd89830f9 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -435,7 +435,7 @@ class URLSearchParams { } } - delete(name) { + delete(name, value = undefined) { if (typeof this !== 'object' || this === null || !(#searchParams in this)) throw new ERR_INVALID_THIS('URLSearchParams'); @@ -445,12 +445,23 @@ class URLSearchParams { const list = this.#searchParams; name = toUSVString(name); - for (let i = 0; i < list.length;) { - const cur = list[i]; - if (cur === name) { - list.splice(i, 2); - } else { - i += 2; + + if (value !== undefined) { + value = toUSVString(value); + for (let i = 0; i < list.length;) { + if (list[i] === name && list[i + 1] === value) { + list.splice(i, 2); + } else { + i += 2; + } + } + } else { + for (let i = 0; i < list.length;) { + if (list[i] === name) { + list.splice(i, 2); + } else { + i += 2; + } } } if (this.#context) { @@ -495,7 +506,7 @@ class URLSearchParams { return values; } - has(name) { + has(name, value = undefined) { if (typeof this !== 'object' || this === null || !(#searchParams in this)) throw new ERR_INVALID_THIS('URLSearchParams'); @@ -505,11 +516,19 @@ class URLSearchParams { const list = this.#searchParams; name = toUSVString(name); + + if (value !== undefined) { + value = toUSVString(value); + } + for (let i = 0; i < list.length; i += 2) { if (list[i] === name) { - return true; + if (value === undefined || list[i + 1] === value) { + return true; + } } } + return false; } |