Merge pull request #461 from javascript-obfuscator/reserved-names-fix

Fixed `reservedNames` option
This commit is contained in:
Timofey Kachalov
2019-12-31 01:37:22 +03:00
committed by GitHub
9 changed files with 54 additions and 8 deletions
+7
View File
@@ -1,5 +1,12 @@
Change Log
v0.19.4
---
* Fixed `reservedNames` option
Thanks to our contributors!
* [kida7](https://github.com/kida7)
v0.19.3
---
* The `splitStrings` option now correctly works with `transformObjectKeys` option
+3 -3
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.19.3",
"version": "0.19.4",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
@@ -116,7 +116,7 @@ export class BaseIdentifierObfuscatingReplacer extends AbstractObfuscatingReplac
* @returns {boolean}
*/
private isReservedName (name: string): boolean {
if (!this.options.reservedNames || !this.options.reservedNames.length) {
if (!this.options.reservedNames.length) {
return false;
}
@@ -304,7 +304,7 @@ describe('LiteralTransformer', () => {
});
});
describe('Variant #12: `reservedNames` option is enabled', () => {
describe('Variant #12: `reservedStrings` option is enabled', () => {
describe('Variant #1: base `reservedStrings` values', () => {
describe('Variant #1: single reserved string value', () => {
const stringLiteralRegExp1: RegExp = /const foo *= *'foo';/;
@@ -0,0 +1,34 @@
import { assert } from 'chai';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../../../../helpers/readFileAsString';
import { JavaScriptObfuscator } from '../../../../../../../src/JavaScriptObfuscatorFacade';
describe('BaseIdentifierObfuscatingReplacer', () => {
describe('Base rule', () => {
describe('Variant #1: default behaviour', () => {
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
reservedNames: ['[abc|ghi]']
}
).getObfuscatedCode();
});
it('Should keep reserved names without transformations when `reservedNames` option is enabled', () => {
assert.match(
obfuscatedCode,
/var *abc *= *0x1; *var *_0x([a-f0-9]){4,6} *= *0x2; *var *ghi *= *0x3;/
);
});
});
});
});