Skip to content

Commit

Permalink
intial
Browse files Browse the repository at this point in the history
  • Loading branch information
debadree25 committed Feb 24, 2023
1 parent 42be7f6 commit f15896c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
Array,
ArrayIsArray,
ArrayPrototypeJoin,
ArrayPrototypeMap,
ArrayPrototypePush,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f15896c

Please sign in to comment.