Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dist/index.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function(){
var object = {
0: 'foo',
bar: 'bar',
2: 'baz'
};
})();