mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed processing of null value in NodeUtils.clone() method
This commit is contained in:
@@ -5,6 +5,10 @@ v0.11.0
|
||||
* **New option:** `log` enables logging of the information to the console.
|
||||
* **New option:** `renameGlobals` allows to enable obfuscation of global variable and function names with declaration.
|
||||
|
||||
v0.10.2
|
||||
---
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/78
|
||||
|
||||
v0.10.1
|
||||
---
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/76
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
@@ -37,9 +37,9 @@
|
||||
"tslib": "1.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "4.0.1",
|
||||
"@types/chai": "4.0.2",
|
||||
"@types/chalk": "0.4.31",
|
||||
"@types/chance": "0.7.33",
|
||||
"@types/chance": "0.7.34",
|
||||
"@types/commander": "2.9.1",
|
||||
"@types/escodegen": "0.0.6",
|
||||
"@types/esprima": "2.1.34",
|
||||
@@ -48,7 +48,7 @@
|
||||
"@types/md5": "2.1.32",
|
||||
"@types/mkdirp": "0.5.0",
|
||||
"@types/mocha": "2.2.41",
|
||||
"@types/node": "8.0.17",
|
||||
"@types/node": "8.0.19",
|
||||
"@types/sinon": "2.3.3",
|
||||
"@types/string-template": "1.0.2",
|
||||
"@types/webpack-env": "1.13.0",
|
||||
@@ -60,7 +60,7 @@
|
||||
"chai": "4.1.0",
|
||||
"coveralls": "2.13.1",
|
||||
"istanbul": "1.1.0-alpha.1",
|
||||
"mocha": "3.4.2",
|
||||
"mocha": "3.5.0",
|
||||
"pre-commit": "1.2.2",
|
||||
"sinon": "2.4.1",
|
||||
"ts-node": "3.3.0",
|
||||
|
||||
@@ -83,7 +83,11 @@ export class CLIUtils {
|
||||
try {
|
||||
config = require(configPath);
|
||||
} catch (e) {
|
||||
config = __non_webpack_require__(configPath);
|
||||
try {
|
||||
config = __non_webpack_require__(configPath);
|
||||
} catch (e) {
|
||||
throw new ReferenceError('Given config path must be a valid file path');
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
|
||||
@@ -46,6 +46,10 @@ export class NodeUtils {
|
||||
*/
|
||||
public static clone <T extends ESTree.Node> (astTree: T): T {
|
||||
const cloneRecursive: (node: T) => T = (node: T) => {
|
||||
if (node === null) {
|
||||
return node;
|
||||
}
|
||||
|
||||
const copy: {[key: string]: any} = {};
|
||||
|
||||
Object
|
||||
|
||||
@@ -49,23 +49,41 @@ describe('CLIUtils', () => {
|
||||
});
|
||||
|
||||
describe('getUserConfig (configPath: string): Object', () => {
|
||||
const configDirName: string = 'test/fixtures';
|
||||
const configFileName: string = 'config.js';
|
||||
const configFilePath: string = `../../../${configDirName}/${configFileName}`;
|
||||
const expectedResult: TInputOptions = {
|
||||
compact: true,
|
||||
selfDefending: false,
|
||||
sourceMap: true
|
||||
};
|
||||
describe('variant #1: valid config file path', () => {
|
||||
const configDirName: string = 'test/fixtures';
|
||||
const configFileName: string = 'config.js';
|
||||
const configFilePath: string = `../../../${configDirName}/${configFileName}`;
|
||||
const expectedResult: TInputOptions = {
|
||||
compact: true,
|
||||
selfDefending: false,
|
||||
sourceMap: true
|
||||
};
|
||||
|
||||
let result: Object;
|
||||
let result: Object;
|
||||
|
||||
before(() => {
|
||||
result = CLIUtils.getUserConfig(configFilePath);
|
||||
before(() => {
|
||||
result = CLIUtils.getUserConfig(configFilePath);
|
||||
});
|
||||
|
||||
it('should return object with user configuration', () => {
|
||||
assert.deepEqual(result, expectedResult);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return object with user configuration', () => {
|
||||
assert.deepEqual(result, expectedResult);
|
||||
describe('variant #2: invalid config file path', () => {
|
||||
const configDirName: string = 'test/fixtures';
|
||||
const configFileName: string = 'configs.js';
|
||||
const configFilePath: string = `../../../${configDirName}/${configFileName}`;
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => CLIUtils.getUserConfig(configFilePath);
|
||||
});
|
||||
|
||||
it('should throw an error if `configFilePath` is not a valid path', () => {
|
||||
assert.throws(testFunc, ReferenceError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -74,12 +92,15 @@ describe('CLIUtils', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
const inputPath: string = `${tmpDir}/${tmpFileName}`;
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
fs.writeFileSync(inputPath, fileContent);
|
||||
testFunc = () => CLIUtils.validateInputPath(inputPath);
|
||||
});
|
||||
|
||||
it('shouldn\'t throw an error if `inputPath` is a valid path', () => {
|
||||
assert.doesNotThrow(() => CLIUtils.validateInputPath(inputPath), ReferenceError);
|
||||
assert.doesNotThrow(testFunc, ReferenceError);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
@@ -91,8 +112,14 @@ describe('CLIUtils', () => {
|
||||
const tmpFileName: string = 'test.js';
|
||||
const inputPath: string = `${tmpDir}/${tmpFileName}`;
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => CLIUtils.validateInputPath(inputPath);
|
||||
});
|
||||
|
||||
it('should throw an error if `inputPath` is not a valid path', () => {
|
||||
assert.throws(() => CLIUtils.validateInputPath(inputPath), ReferenceError);
|
||||
assert.throws(testFunc, ReferenceError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -100,12 +127,15 @@ describe('CLIUtils', () => {
|
||||
const tmpFileName: string = 'test.ts';
|
||||
const inputPath: string = `${tmpDir}/${tmpFileName}`;
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
fs.writeFileSync(inputPath, fileContent);
|
||||
testFunc = () => CLIUtils.validateInputPath(inputPath);
|
||||
});
|
||||
|
||||
it('should throw an error if `inputPath` is a file name has invalid extension', () => {
|
||||
assert.throws(() => CLIUtils.validateInputPath(inputPath), ReferenceError);
|
||||
assert.throws(testFunc, ReferenceError);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
|
||||
@@ -27,52 +27,98 @@ describe('NodeUtils', () => {
|
||||
});
|
||||
|
||||
describe('clone <T extends ESTree.Node> (astTree: T): T', () => {
|
||||
let programNode: ESTree.Program,
|
||||
expectedProgramNode: ESTree.Program;
|
||||
describe('variant #1: simple AST-tree', () => {
|
||||
let programNode: ESTree.Program,
|
||||
expectedProgramNode: ESTree.Program;
|
||||
|
||||
before(() => {
|
||||
// actual AST tree
|
||||
const expressionStatementNode1: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
const expressionStatementNode2: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
before(() => {
|
||||
// actual AST tree
|
||||
const expressionStatementNode1: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
const expressionStatementNode2: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
|
||||
const ifStatementBlockStatementNode1: ESTree.BlockStatement = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode1,
|
||||
expressionStatementNode2
|
||||
]);
|
||||
const ifStatementBlockStatementNode1: ESTree.BlockStatement = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode1,
|
||||
expressionStatementNode2
|
||||
]);
|
||||
|
||||
const ifStatementNode1: ESTree.IfStatement = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementBlockStatementNode1
|
||||
);
|
||||
const ifStatementNode1: ESTree.IfStatement = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementBlockStatementNode1
|
||||
);
|
||||
|
||||
// expected AST tree
|
||||
const expressionStatementNode3: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
const expressionStatementNode4: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
// expected AST tree
|
||||
const expressionStatementNode3: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
const expressionStatementNode4: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(Nodes.getIdentifierNode('identifier'));
|
||||
|
||||
const ifStatementBlockStatementNode2: ESTree.BlockStatement = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode3,
|
||||
expressionStatementNode4
|
||||
]);
|
||||
const ifStatementBlockStatementNode2: ESTree.BlockStatement = Nodes.getBlockStatementNode([
|
||||
expressionStatementNode3,
|
||||
expressionStatementNode4
|
||||
]);
|
||||
|
||||
const ifStatementNode2: ESTree.IfStatement = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementBlockStatementNode2
|
||||
);
|
||||
const ifStatementNode2: ESTree.IfStatement = Nodes.getIfStatementNode(
|
||||
Nodes.getLiteralNode(true),
|
||||
ifStatementBlockStatementNode2
|
||||
);
|
||||
|
||||
programNode = NodeUtils.clone(
|
||||
Nodes.getProgramNode([
|
||||
ifStatementNode1
|
||||
])
|
||||
);
|
||||
expectedProgramNode = NodeUtils.parentize(
|
||||
Nodes.getProgramNode([
|
||||
ifStatementNode2
|
||||
])
|
||||
);
|
||||
programNode = NodeUtils.clone(
|
||||
Nodes.getProgramNode([
|
||||
ifStatementNode1
|
||||
])
|
||||
);
|
||||
expectedProgramNode = NodeUtils.parentize(
|
||||
Nodes.getProgramNode([
|
||||
ifStatementNode2
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('should clone given AST-tree', () => {
|
||||
assert.deepEqual(programNode, expectedProgramNode);
|
||||
});
|
||||
});
|
||||
|
||||
it('should clone given AST-tree', () => {
|
||||
assert.deepEqual(programNode, expectedProgramNode);
|
||||
describe('variant #2: array expression with `null` element', () => {
|
||||
let programNode: ESTree.Program,
|
||||
expectedProgramNode: ESTree.Program;
|
||||
|
||||
before(() => {
|
||||
// actual AST tree
|
||||
const arrayExpressionNode: ESTree.ArrayExpression = Nodes.getArrayExpressionNode([
|
||||
Nodes.getLiteralNode(1),
|
||||
Nodes.getLiteralNode(2),
|
||||
<any>null,
|
||||
Nodes.getLiteralNode(4)
|
||||
]);
|
||||
const expressionStatementNode: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(
|
||||
arrayExpressionNode
|
||||
);
|
||||
|
||||
// expected AST tree
|
||||
const expectedArrayExpressionNode: ESTree.ArrayExpression = Nodes.getArrayExpressionNode([
|
||||
Nodes.getLiteralNode(1),
|
||||
Nodes.getLiteralNode(2),
|
||||
<any>null,
|
||||
Nodes.getLiteralNode(4)
|
||||
]);
|
||||
const expectedExpressionStatementNode: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(
|
||||
expectedArrayExpressionNode
|
||||
);
|
||||
|
||||
programNode = NodeUtils.clone(
|
||||
Nodes.getProgramNode([
|
||||
expressionStatementNode
|
||||
])
|
||||
);
|
||||
expectedProgramNode = NodeUtils.parentize(
|
||||
Nodes.getProgramNode([
|
||||
expectedExpressionStatementNode
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('should clone given AST-tree', () => {
|
||||
assert.deepEqual(programNode, expectedProgramNode);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/chai@4.0.1":
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.0.1.tgz#37fea779617cfec3fd2b19a0247e8bbdd5133bf6"
|
||||
"@types/chai@4.0.2":
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.0.2.tgz#cce9666f5ee2fa27ffd505d2dfaf53bb02ed2584"
|
||||
|
||||
"@types/chalk@0.4.31":
|
||||
version "0.4.31"
|
||||
resolved "https://registry.yarnpkg.com/@types/chalk/-/chalk-0.4.31.tgz#a31d74241a6b1edbb973cf36d97a2896834a51f9"
|
||||
|
||||
"@types/chance@0.7.33":
|
||||
version "0.7.33"
|
||||
resolved "https://registry.yarnpkg.com/@types/chance/-/chance-0.7.33.tgz#9666ae5c8f602a14a67e5b608dabf1a7853a1e28"
|
||||
"@types/chance@0.7.34":
|
||||
version "0.7.34"
|
||||
resolved "https://registry.yarnpkg.com/@types/chance/-/chance-0.7.34.tgz#270ec0e23feafdee471b9d2f053f9a2ff922270e"
|
||||
|
||||
"@types/commander@2.9.1":
|
||||
version "2.9.1"
|
||||
@@ -56,10 +56,14 @@
|
||||
version "2.2.41"
|
||||
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.41.tgz#e27cf0817153eb9f2713b2d3f6c68f1e1c3ca608"
|
||||
|
||||
"@types/node@*", "@types/node@8.0.17":
|
||||
"@types/node@*":
|
||||
version "8.0.17"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.17.tgz#677bc8c118cfb76013febb62ede1f31d2c7222a1"
|
||||
|
||||
"@types/node@8.0.19":
|
||||
version "8.0.19"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.19.tgz#e46e2b0243de7d03f15b26b45c59ebb84f657a4e"
|
||||
|
||||
"@types/sinon@2.3.3":
|
||||
version "2.3.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-2.3.3.tgz#1f20b96f954b4997a09c1c0a20264aaba6b00147"
|
||||
@@ -68,7 +72,7 @@
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/string-template/-/string-template-1.0.2.tgz#363b273c9b456705e3111e3571e9248f6474eba4"
|
||||
|
||||
"@types/webpack-env@^1.13.0":
|
||||
"@types/webpack-env@1.13.0":
|
||||
version "1.13.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.0.tgz#3044381647e11ee973c5af2e925323930f691d80"
|
||||
|
||||
@@ -1203,13 +1207,7 @@ date-now@^0.1.4:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"
|
||||
|
||||
debug@2.6.0, debug@^2.1.1, debug@^2.2.0:
|
||||
version "2.6.0"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.0.tgz#bc596bcabe7617f11d9fa15361eded5608b8499b"
|
||||
dependencies:
|
||||
ms "0.7.2"
|
||||
|
||||
debug@^2.3.3, debug@^2.6.3:
|
||||
debug@2.6.8, debug@^2.1.1, debug@^2.2.0, debug@^2.3.3, debug@^2.6.3:
|
||||
version "2.6.8"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
|
||||
dependencies:
|
||||
@@ -2643,13 +2641,13 @@ mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.1, mkdirp@~0.5.0:
|
||||
dependencies:
|
||||
minimist "0.0.8"
|
||||
|
||||
mocha@3.4.2:
|
||||
version "3.4.2"
|
||||
resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.4.2.tgz#d0ef4d332126dbf18d0d640c9b382dd48be97594"
|
||||
mocha@3.5.0:
|
||||
version "3.5.0"
|
||||
resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.5.0.tgz#1328567d2717f997030f8006234bce9b8cd72465"
|
||||
dependencies:
|
||||
browser-stdout "1.3.0"
|
||||
commander "2.9.0"
|
||||
debug "2.6.0"
|
||||
debug "2.6.8"
|
||||
diff "3.2.0"
|
||||
escape-string-regexp "1.0.5"
|
||||
glob "7.1.1"
|
||||
@@ -2659,10 +2657,6 @@ mocha@3.4.2:
|
||||
mkdirp "0.5.1"
|
||||
supports-color "3.1.2"
|
||||
|
||||
ms@0.7.2:
|
||||
version "0.7.2"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765"
|
||||
|
||||
ms@2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
||||
|
||||
Reference in New Issue
Block a user