fix: support constructor and __proto__ parameters in Parse URI (#2578)

This commit is contained in:
mansiverma897993 2026-06-19 13:19:47 +05:30
parent 7413e911c2
commit f1e8282cb1
2 changed files with 30 additions and 5 deletions

View File

@ -33,7 +33,7 @@ class ParseURI extends Operation {
* @returns {string}
*/
run(input, args) {
const uri = url.parse(input, true);
const uri = url.parse(input, false);
let output = "";
@ -43,7 +43,20 @@ class ParseURI extends Operation {
if (uri.port) output += "Port:\t\t" + uri.port + "\n";
if (uri.pathname) output += "Path name:\t" + uri.pathname + "\n";
if (uri.query) {
const keys = Object.keys(uri.query);
const queryObj = Object.create(null);
for (const [key, value] of new URLSearchParams(uri.query)) {
if (Object.prototype.hasOwnProperty.call(queryObj, key)) {
if (Array.isArray(queryObj[key])) {
queryObj[key].push(value);
} else {
queryObj[key] = [queryObj[key], value];
}
} else {
queryObj[key] = value;
}
}
const keys = Object.keys(queryObj);
let padding = 0;
keys.forEach(k => {
@ -51,10 +64,10 @@ class ParseURI extends Operation {
});
output += "Arguments:\n";
for (const key in uri.query) {
for (const key in queryObj) {
output += "\t" + key.padEnd(padding, " ");
if (uri.query[key].length) {
output += " = " + uri.query[key] + "\n";
if (queryObj[key].length) {
output += " = " + queryObj[key] + "\n";
} else {
output += "\n";
}

View File

@ -728,6 +728,18 @@ Arguments:
assert.strictEqual(result.toString(), expected);
}),
it("Parse URI with constructor and __proto__ arguments", () => {
const result = chef.parseURI("https://example.com/?constructor=ok&__proto__=hello");
const expected = `Protocol: https:
Hostname: example.com
Path name: /
Arguments:
\tconstructor = ok
\t__proto__ = hello
`;
assert.strictEqual(result.toString(), expected);
}),
it("Parse user agent", () => {
const result = chef.parseUserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0 ");
const expected = `Browser