diff --git a/CHANGELOG.md b/CHANGELOG.md index 2956b9345..eb4ce7892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log +v5.4.4 +--- +* Fixed `Invalid regular expression` error when obfuscating code that uses ES2025 RegExp pattern modifiers (e.g. `/(?i:abc)/`). Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1410 + v5.4.3 --- * Fixed `controlFlowFlattening` occasionally dropping the `?.` short-circuit on `foo?.(arg)` calls, causing `TypeError: is not a function`. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1408 diff --git a/package.json b/package.json index 71bad57d9..1caf7a7f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "5.4.3", + "version": "5.4.4", "description": "JavaScript obfuscator", "keywords": [ "obfuscator", diff --git a/src/constants/EcmaVersion.ts b/src/constants/EcmaVersion.ts index 6b26b2767..790a021d2 100644 --- a/src/constants/EcmaVersion.ts +++ b/src/constants/EcmaVersion.ts @@ -1,3 +1,3 @@ import * as acorn from 'acorn'; -export const ecmaVersion = 13; +export const ecmaVersion = 2026; diff --git a/test/functional-tests/issues/issue1410.spec.ts b/test/functional-tests/issues/issue1410.spec.ts new file mode 100644 index 000000000..9cff6d239 --- /dev/null +++ b/test/functional-tests/issues/issue1410.spec.ts @@ -0,0 +1,46 @@ +import { assert } from 'chai'; +import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; +import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; + +// +// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1410 +// +describe('Issue #1410', () => { + describe('ES2025 RegExp pattern modifiers should be parsed without errors', () => { + describe('inline case-insensitive modifier `(?i:...)`', () => { + let obfuscatedCode: string; + + before(() => { + const code: string = `console.log(/(?i:abc)/.test('ABC'));`; + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); + }); + + it('should not throw an `Invalid regular expression` error and should preserve the regex literal', () => { + assert.match(obfuscatedCode, /\/\(\?i:abc\)\//); + }); + + it('should produce semantically equivalent code', () => { + assert.isTrue(eval(`/(?i:abc)/.test('ABC')`)); + }); + }); + + describe('disabled modifier `(?-i:...)` within a case-insensitive regex', () => { + let obfuscatedCode: string; + + before(() => { + const code: string = `console.log(/(?-i:abc)/i.test('ABC'));`; + + obfuscatedCode = JavaScriptObfuscator.obfuscate(code, { + ...NO_ADDITIONAL_NODES_PRESET + }).getObfuscatedCode(); + }); + + it('should not throw an `Invalid regular expression` error and should preserve the regex literal', () => { + assert.match(obfuscatedCode, /\/\(\?-i:abc\)\/i/); + }); + }); + }); +});