mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge pull request #502 from javascript-obfuscator/transform-object-keys-numeric-keys
Fixed numeric keys removal on extract during object keys transformation
This commit is contained in:
@@ -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
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+8
-2
@@ -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)) {
|
||||
|
||||
+28
@@ -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', () => {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
(function(){
|
||||
var object = {
|
||||
0: 'foo',
|
||||
bar: 'bar',
|
||||
2: 'baz'
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user