diff --git a/lib/internal/url.js b/lib/internal/url.js index 23340a3e5c1a01..0d34bcfd76a4a6 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -2,6 +2,7 @@ const { Array, + ArrayIsArray, ArrayPrototypeJoin, ArrayPrototypeMap, ArrayPrototypePush, @@ -211,7 +212,17 @@ class URLSearchParams { const desc = ReflectGetOwnPropertyDescriptor(init, key); if (desc !== undefined && desc.enumerable) { const typedKey = toUSVString(key); - const typedValue = toUSVString(init[key]); + let typedValue = ''; + if (ArrayIsArray(init[key])) { + const len = init[key].length; + for (let j = 0; j < len; j++) { + typedValue += toUSVString(init[key][j]); + if (j < len - 1) + typedValue += ','; + } + } else { + typedValue = toUSVString(init[key]); + } // Two different key may result same after `toUSVString()`, we only // leave the later one. Refers to WPT. @@ -1017,12 +1028,17 @@ function serializeParams(array) { const firstEncodedParam = encodeStr(array[0], noEscape, paramHexTable); const firstEncodedValue = encodeStr(array[1], noEscape, paramHexTable); - let output = `${firstEncodedParam}=${firstEncodedValue}`; + let output = firstEncodedParam; + output += '='; + output += firstEncodedValue; for (let i = 2; i < len; i += 2) { const encodedParam = encodeStr(array[i], noEscape, paramHexTable); const encodedValue = encodeStr(array[i + 1], noEscape, paramHexTable); - output += `&${encodedParam}=${encodedValue}`; + output += '&'; + output += encodedParam; + output += '='; + output += encodedValue; } return output; diff --git a/lib/internal/util.js b/lib/internal/util.js index 5665923a2cd297..c51209e61d76d9 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -72,7 +72,7 @@ const colorRegExp = /\u001b\[\d\d?m/g; // eslint-disable-line no-control-regex const unpairedSurrogateRe = /(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/; function toUSVString(val) { - const str = `${val}`; + const str = '' + val; // As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are // slower than `unpairedSurrogateRe.exec()`. const match = RegExpPrototypeExec(unpairedSurrogateRe, str);