Fixed numeric keys removal on extract during object keys transformation

This commit is contained in:
sanex3339
2020-01-15 22:55:09 +03:00
parent c3b0b4f369
commit a3c7bd10c6
7 changed files with 47 additions and 5 deletions
+1
View File
@@ -3,6 +3,7 @@ Change Log
v0.23.0
---
* **New option:** `shuffleStringArray` randomly shuffles string array items
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/498
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/494
* **Internal change:** switched AST parser from `espree` on `acorn`
* **Internal refactoring:** refactoring of string array storage and related things
+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
File diff suppressed because one or more lines are too long
@@ -59,8 +59,14 @@ export abstract class AbstractPropertiesExtractor implements IPropertiesExtracto
const propertyKeyNode: ESTree.Expression = propertyNode.key;
if (NodeGuards.isLiteralNode(propertyKeyNode) && typeof propertyKeyNode.value === 'string') {
return propertyKeyNode.value;
if (
NodeGuards.isLiteralNode(propertyKeyNode)
&& (
typeof propertyKeyNode.value === 'string'
|| typeof propertyKeyNode.value === 'number'
)
) {
return propertyKeyNode.value.toString();
}
if (NodeGuards.isIdentifierNode(propertyKeyNode)) {
@@ -396,6 +396,34 @@ describe('ObjectExpressionKeysTransformer', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('Variant #13: should keep numeric object keys', () => {
const match: string = `` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['0'] *= *'foo';` +
`${variableMatch}\\['bar'] *= *'bar';` +
`${variableMatch}\\['2'] *= *'baz';` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/numeric-keys.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
).getObfuscatedCode();
});
it('should correctly transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
describe('member expression as host of object expression', () => {
@@ -0,0 +1,7 @@
(function(){
var object = {
0: 'foo',
bar: 'bar',
2: 'baz'
};
})();