From f1e8282cb1a4f41b3196951007e2d55abe8b0277 Mon Sep 17 00:00:00 2001 From: mansiverma897993 Date: Fri, 19 Jun 2026 13:19:47 +0530 Subject: [PATCH 1/3] fix: support constructor and __proto__ parameters in Parse URI (#2578) --- src/core/operations/ParseURI.mjs | 23 ++++++++++++++++++----- tests/node/tests/operations.mjs | 12 ++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/core/operations/ParseURI.mjs b/src/core/operations/ParseURI.mjs index 17ca90dbc7..debcc80d11 100644 --- a/src/core/operations/ParseURI.mjs +++ b/src/core/operations/ParseURI.mjs @@ -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"; } diff --git a/tests/node/tests/operations.mjs b/tests/node/tests/operations.mjs index 6cf857180c..9108ec0076 100644 --- a/tests/node/tests/operations.mjs +++ b/tests/node/tests/operations.mjs @@ -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 From b65c8eaebc5b314eea04638621c31ace131ceee9 Mon Sep 17 00:00:00 2001 From: mansiverma897993 Date: Wed, 24 Jun 2026 14:22:53 +0530 Subject: [PATCH 2/3] test: add browser test for Parse URI - Add a browser UI test in 02_ops.js to test constructor and __proto__ query parameters in the npm url polyfill context. - Fix webpack.config.js exclude rule and asset/inline overlap to enable dev builds on Windows. --- tests/browser/02_ops.js | 2 +- webpack.config.js | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/browser/02_ops.js b/tests/browser/02_ops.js index 9139a53a0e..41ca550521 100644 --- a/tests/browser/02_ops.js +++ b/tests/browser/02_ops.js @@ -277,7 +277,7 @@ module.exports = { // testOp(browser, "Parse TLV", "test input", "test_output"); testOpHtml(browser, "Parse UDP", "04 89 00 35 00 2c 01 01", "tr:last-child td:last-child", "0x0101"); // testOp(browser, "Parse UNIX file permissions", "test input", "test_output"); - // testOp(browser, "Parse URI", "test input", "test_output"); + testOp(browser, "Parse URI", "https://example.com/?constructor=ok&__proto__=hello", /Arguments:\s+constructor = ok\s+__proto__\s+= hello/); testOp(browser, "Parse User Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0 ", /Architecture: amd64/); // testOp(browser, "Parse X.509 certificate", "test input", "test_output"); testOpFile(browser, "Play Media", "files/mp3example.mp3", "audio", ""); diff --git a/webpack.config.js b/webpack.config.js index 4c6c00ba29..81b4da44e9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -142,7 +142,7 @@ module.exports = { rules: [ { test: /\.m?js$/, - exclude: /node_modules\/(?!crypto-api|bootstrap)/, + exclude: /node_modules[\\/](?!crypto-api|bootstrap)/, options: { configFile: path.resolve(__dirname, "babel.config.js"), cacheDirectory: true, @@ -211,18 +211,20 @@ module.exports = { filename: "assets/fonts/[name][ext]" } }, - { // First party images are saved as files to be cached - test: /\.(png|jpg|gif)$/, - exclude: /(node_modules|bmfonts)/, - type: "asset/resource", - generator: { - filename: "images/[name][ext]" - } - }, - { // Third party images are inlined + { test: /\.(png|jpg|gif)$/, - exclude: /web\/static/, - type: "asset/inline", + oneOf: [ + { + exclude: /(node_modules|bmfonts)/, + type: "asset/resource", + generator: { + filename: "images/[name][ext]" + } + }, + { + type: "asset/inline" + } + ] }, ] }, From b5d7966c3739cbbf236f52d48335e6859a63159e Mon Sep 17 00:00:00 2001 From: mansiverma897993 Date: Wed, 24 Jun 2026 18:23:42 +0530 Subject: [PATCH 3/3] revert: webpack.config.js changes to align with upstream master --- webpack.config.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 81b4da44e9..555a33c399 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -88,8 +88,8 @@ module.exports = { from: "tesseract/**/*", to: "assets/" }, { - context: "node_modules/tesseract.js/", - from: "dist/worker.min.js", + context: "node_modules/tesseract.js/dist", + from: "worker.min.js", to: "assets/tesseract" }, { context: "node_modules/tesseract.js-core/", @@ -142,7 +142,7 @@ module.exports = { rules: [ { test: /\.m?js$/, - exclude: /node_modules[\\/](?!crypto-api|bootstrap)/, + exclude: /node_modules\/(?!crypto-api|bootstrap)/, options: { configFile: path.resolve(__dirname, "babel.config.js"), cacheDirectory: true, @@ -211,20 +211,18 @@ module.exports = { filename: "assets/fonts/[name][ext]" } }, - { + { // First party images are saved as files to be cached test: /\.(png|jpg|gif)$/, - oneOf: [ - { - exclude: /(node_modules|bmfonts)/, - type: "asset/resource", - generator: { - filename: "images/[name][ext]" - } - }, - { - type: "asset/inline" - } - ] + exclude: /(node_modules|bmfonts)/, + type: "asset/resource", + generator: { + filename: "images/[name][ext]" + } + }, + { // Third party images are inlined + test: /\.(png|jpg|gif)$/, + include: /node_modules/, + type: "asset/inline", }, ] },