diff --git a/package-lock.json b/package-lock.json index 7117787..cddaeea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2629,13 +2629,10 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.12.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", - "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", - "dev": true, - "dependencies": { - "undici-types": "~5.26.4" - } + "version": "20.8.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.3.tgz", + "integrity": "sha512-jxiZQFpb+NlH5kjW49vXxvxTjeeqlbsnTAdBTKpzEdPs9itay7MscYXz3Fo9VYFEsfQ6LJFitHad3faerLAjCw==", + "dev": true }, "node_modules/@types/normalize-package-data": { "version": "2.4.4", @@ -12199,12 +12196,6 @@ "node": ">=14.0" } }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true - }, "node_modules/unicode-emoji-modifier-base": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unicode-emoji-modifier-base/-/unicode-emoji-modifier-base-1.0.0.tgz", diff --git a/package.json b/package.json index ca40f1e..d96cc21 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "scripts": { "build": "tsc", "build-worker": "node worker/build.js", - "test": "npm run-script build-worker && node --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --collectCoverage --coverageProvider=v8", - "test-debug": "npm run-script build-worker && node --experimental-vm-modules --inspect-brk node_modules/jest/bin/jest.js --runInBand", + "test": "npm run-script build-worker && node --no-experimental-fetch --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --collectCoverage --coverageProvider=v8", + "test-debug": "npm run-script build-worker && node --no-experimental-fetch --experimental-vm-modules --inspect-brk node_modules/jest/bin/jest.js --runInBand", "format": "prettier --write '*.{json,js}' 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'", "lint": "eslint --max-warnings=0 src && prettier --check '*.{json,js}' 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'", "prepack": "npm run-script test && npm run-script lint && npm run-script build", @@ -110,5 +110,8 @@ }, "dependencies": { "worktop": "0.7.3" + }, + "overrides": { + "@types/node": "20.8.3" } } diff --git a/src/processConditionals.ts b/src/processConditionals.ts index 0a381d1..a6a77a4 100644 --- a/src/processConditionals.ts +++ b/src/processConditionals.ts @@ -125,16 +125,25 @@ function esi_eval_var_in_when_tag( match: [String: string, ...args: string[]], ): string { const varInTag = esi_eval_var(eventData, match); - - const number = parseInt(varInTag, 10); - if (number) { - return number.toString(); + // we have to check varInTag is *actually* a number and doesn't just have leading numbers in it + if (strIsNumber(varInTag)) { + return parseInt(varInTag, 10).toString(); } else { // Change to replaceAll once upgraded node return "'" + varInTag.replace(/'/g, "\\'") + "'"; } } +/** + * Evaluates str and returns if it *actually* is a number not just a str with leading numbers + * + * @param {string} str string to check + * @returns {boolean} check result + */ +function strIsNumber(str: string): boolean { + return !isNaN(Number(str)); +} + /** * Takes a condition string and splits it into its two sides and operator * passes that to the tester and returns the result diff --git a/test/esi.spec.ts b/test/esi.spec.ts index f0d97c5..29a92b3 100644 --- a/test/esi.spec.ts +++ b/test/esi.spec.ts @@ -1911,3 +1911,33 @@ test("TEST 50: Multiple ESI Args make it all the way through", async () => { `esi_args1=1&esi_args2=2&esi_args3=3&esi_args4=4`, ); }); + +describe("TEST 51: ESI Args that lead with ints shouldn't convert to ints", () => { + const checks = [ + { arg: "1719,2405", result: "first-lineage" }, + { arg: "1719,1732", result: "second-lineage" }, + { arg: "1719,1918", result: "third-lineage" }, + { arg: "1719,1922", result: "forth-lineage" }, + { arg: "1719,1926", result: "fith-lineage" }, + ]; + + const url = `/esi/test-51`; + checks.forEach(function (check) { + it(check.result, async () => { + routeHandler.add(url, function (req, res) { + res.writeHead(200, esiHead); + res.end(` + first-lineage + second-lineage + third-lineage + forth-lineage + fith-lineage +`); + }); + const res = await makeRequest(`${url}?esi_lineage=${check.arg}`); + expect(res.ok).toBeTruthy(); + expect(await res.text()).toEqual(check.result); + expect(checkSurrogate(res)).toBeTruthy(); + }); + }); +});