diff --git a/CHANGELOG.md b/CHANGELOG.md index 0203f6efc..8eeaafc7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log +v5.4.1 +--- +* Fixed missing space between keywords (`return`, `throw`, `typeof`) and Unicode surrogate pair identifiers in compact mode. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1112 + v5.4.0 --- * Add support for `import attributes`. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1256 diff --git a/package.json b/package.json index 70760a6b8..6965d2b8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "5.4.0", + "version": "5.4.1", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", @@ -21,7 +21,7 @@ }, "types": "typings/index.d.ts", "dependencies": { - "@javascript-obfuscator/escodegen": "2.4.0", + "@javascript-obfuscator/escodegen": "2.4.1", "@javascript-obfuscator/estraverse": "5.4.0", "@vercel/blob": ">=0.23.0", "acorn": "8.15.0", diff --git a/test/functional-tests/issues/fixtures/issue1112.js b/test/functional-tests/issues/fixtures/issue1112.js new file mode 100644 index 000000000..2002d83fb --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1112.js @@ -0,0 +1,3 @@ +(function(𝐜𝐨𝐧𝐭𝐞𝐱𝐭) { + return 𝐜𝐨𝐧𝐭𝐞𝐱𝐭; +})(42) diff --git a/test/functional-tests/issues/issue1112.spec.ts b/test/functional-tests/issues/issue1112.spec.ts new file mode 100644 index 000000000..8a8508b6c --- /dev/null +++ b/test/functional-tests/issues/issue1112.spec.ts @@ -0,0 +1,39 @@ +import { assert } from 'chai'; +import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; +import { readFileAsString } from '../../helpers/readFileAsString'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; + +// +// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1112 +// +describe('Issue #1112', () => { + describe('Unicode mathematical bold identifiers should have correct spacing after keywords', () => { + let testFunc: () => void; + + before(() => { + const code: string = readFileAsString(__dirname + '/fixtures/issue1112.js'); + + testFunc = () => { + const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET, + reservedNames: ['𝐜𝐨𝐧𝐭𝐞𝐱𝐭'], + compact: true, + seed: 1 + }).getObfuscatedCode(); + + const result = eval(obfuscatedCode); + + if (result !== 42) { + throw new Error( + `Expected 42, got ${result}. ` + + `Missing space between keyword and Unicode identifier.` + ); + } + }; + }); + + it('should produce valid code with Unicode surrogate pair identifiers', () => { + assert.doesNotThrow(testFunc); + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index 45b47f685..5eaf4644a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -329,10 +329,10 @@ resolved "https://registry.yarnpkg.com/@istanbuljs/schema/-/schema-0.1.3.tgz#e45e384e4b8ec16bce2fd903af78450f6bf7ec98" integrity sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA== -"@javascript-obfuscator/escodegen@2.4.0": - version "2.4.0" - resolved "https://registry.yarnpkg.com/@javascript-obfuscator/escodegen/-/escodegen-2.4.0.tgz#9d2b19b94793106cafa5cd5041c4e40d42943fb7" - integrity sha512-h9cJ/qb3Y3c1jMQPWypt2CGTFgP34V5OtWLqoOCjV6CT/DUXMZFpoTAfDHpuUrRP0oxNd0UwnVAsPtPuYsoXxQ== +"@javascript-obfuscator/escodegen@2.4.1": + version "2.4.1" + resolved "https://registry.yarnpkg.com/@javascript-obfuscator/escodegen/-/escodegen-2.4.1.tgz#6062541cb3027912e9304dd15f8a5ee5946de247" + integrity sha512-YrEJJDr4cb+pIQKWzHFoDlDkQzatcrNB6OhAD6iTSwiKwzZUMVdobwbOuLpF4EiLxUj0qP28Xl1saTHYzIPCLg== dependencies: "@javascript-obfuscator/estraverse" "^5.3.0" esprima "^4.0.1"