mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Prevent properties with get and set kinds from extraction with transformObjectKeys option. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/707
This commit is contained in:
+29
@@ -1820,5 +1820,34 @@ describe('ObjectExpressionKeysTransformer', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #11: `get` and `set` property kinds', () => {
|
||||
const match: string = `` +
|
||||
`const ${variableMatch} *= *{ *` +
|
||||
`get \'baz\' *\\(\\) *{ *return 0x2; *}, *` +
|
||||
`set \'bark\' *\\(${variableMatch}\\) *{ *this\\[\'bark\'] *= *${variableMatch}; *} *` +
|
||||
`}; *` +
|
||||
`${variableMatch}\\[\'bar\'] *= *0x1;` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/get-set-property-kind.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should keep property nodes with `get` and `set` kind in the object', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
(function(){
|
||||
const foo = {
|
||||
bar: 1,
|
||||
get baz() { return 2; },
|
||||
set bark(value) { this.bark = value; }
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user