Browse Source

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

Fixed `reservedNames` option
Timofey Kachalov 5 years ago
parent
commit
97aa1fd9be

+ 7 - 0
CHANGELOG.md

@@ -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

File diff suppressed because it is too large
+ 0 - 0
dist/index.browser.js


File diff suppressed because it is too large
+ 0 - 0
dist/index.cli.js


File diff suppressed because it is too large
+ 0 - 0
dist/index.js


+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "javascript-obfuscator",
-  "version": "0.19.3",
+  "version": "0.19.4",
   "description": "JavaScript obfuscator",
   "keywords": [
     "obfuscator",

+ 1 - 1
src/node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer.ts

@@ -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;
         }
 

+ 1 - 1
test/functional-tests/node-transformers/obfuscating-transformers/literal-transformer/LiteralTransformer.spec.ts

@@ -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';/;

+ 34 - 0
test/functional-tests/node-transformers/obfuscating-transformers/literal-transformer/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer.spec.ts

@@ -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;/
+                );
+            });
+        });
+    });
+});

+ 5 - 0
test/functional-tests/node-transformers/obfuscating-transformers/literal-transformer/obfuscating-replacers/identifier-obfuscating-replacers/fixtures/simple-input.js

@@ -0,0 +1,5 @@
+(function () {
+    var abc = 1;
+    var def = 2;
+    var ghi = 3;
+})();

Some files were not shown because too many files changed in this diff