diff --git a/CHANGELOG.md b/CHANGELOG.md index edb665ad8..0c4b66d1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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 +* Fixed `domainLock` being case-sensitive — domain values are now normalized to lowercase. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1182 * Removed `source-map-support` runtime dependency. Use `node --enable-source-maps` instead. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1149 v5.4.0 diff --git a/src/options/normalizer-rules/DomainLockRule.ts b/src/options/normalizer-rules/DomainLockRule.ts index 030f035f4..677b645ca 100644 --- a/src/options/normalizer-rules/DomainLockRule.ts +++ b/src/options/normalizer-rules/DomainLockRule.ts @@ -13,7 +13,7 @@ export const DomainLockRule: TOptionsNormalizerRule = (options: IOptions): IOpti const normalizedDomains: string[] = []; for (const domain of options.domainLock) { - normalizedDomains.push(Utils.extractDomainFrom(domain)); + normalizedDomains.push(Utils.extractDomainFrom(domain).toLowerCase()); } options = { diff --git a/test/functional-tests/issues/fixtures/issue1182.js b/test/functional-tests/issues/fixtures/issue1182.js new file mode 100644 index 000000000..8e2f88daa --- /dev/null +++ b/test/functional-tests/issues/fixtures/issue1182.js @@ -0,0 +1 @@ +var result = 42; diff --git a/test/functional-tests/issues/issue1182.spec.ts b/test/functional-tests/issues/issue1182.spec.ts new file mode 100644 index 000000000..428e8c9c2 --- /dev/null +++ b/test/functional-tests/issues/issue1182.spec.ts @@ -0,0 +1,43 @@ +import { assert } from 'chai'; + +import { DomainLockRule } from '../../../src/options/normalizer-rules/DomainLockRule'; +import { IOptions } from '../../../src/interfaces/options/IOptions'; + +// +// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1182 +// +describe('Issue #1182', () => { + describe('domainLock should be case-insensitive', () => { + it('should normalize mixed-case domain to lowercase', () => { + const options = DomainLockRule({ + domainLock: ['Example.COM'] + } as IOptions); + + assert.deepEqual(options.domainLock, ['example.com']); + }); + + it('should normalize domain with subdomain to lowercase', () => { + const options = DomainLockRule({ + domainLock: ['.Example.COM'] + } as IOptions); + + assert.deepEqual(options.domainLock, ['.example.com']); + }); + + it('should normalize multiple mixed-case domains', () => { + const options = DomainLockRule({ + domainLock: ['Foo.Bar.COM', 'EXAMPLE.ORG'] + } as IOptions); + + assert.deepEqual(options.domainLock, ['foo.bar.com', 'example.org']); + }); + + it('should not change already-lowercase domains', () => { + const options = DomainLockRule({ + domainLock: ['example.com'] + } as IOptions); + + assert.deepEqual(options.domainLock, ['example.com']); + }); + }); +});