Merge pull request #457 from javascript-obfuscator/split-string-template-literal

The `splitStrings` option now affects template literal strings
This commit is contained in:
Timofey Kachalov
2019-12-29 12:14:28 +03:00
committed by GitHub
8 changed files with 50 additions and 9 deletions
+5
View File
@@ -1,5 +1,10 @@
Change Log
v0.19.1
---
* The `splitStrings` option now affects template literal strings
v0.19.0
---
* **New option:** `splitStrings` splits literal strings into chunks with length of `splitStringsChunkLength` option value
+3 -3
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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.19.0",
"version": "0.19.1",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
@@ -56,7 +56,7 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer {
switch (transformationStage) {
case TransformationStage.Converting:
return {
leave: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
enter: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
if (parentNode && TemplateLiteralTransformer.isValidTemplateLiteralNode(node, parentNode)) {
return this.transformNode(node, parentNode);
}
@@ -94,7 +94,42 @@ describe('SplitStringTransformer', () => {
});
});
describe('Variant #6: object key string literal', () => {
describe('Variant #6: unicode escape sequence', () => {
it('should convert strings to unicode escape sequence view', () => {
const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
splitStrings: true,
splitStringsChunkLength: 2,
unicodeEscapeSequence: true
}
).getObfuscatedCode();
assert.match(obfuscatedCode, /^var *test *= *'\\x61\\x62' *\+ *'\\x63\\x64' *\+ *'\\x65\\x66' *\+ *'\\x67';$/);
});
});
describe('Variant #7: template literal string', () => {
it('should apply string splitting on template literal strings', () => {
const code: string = readFileAsString(__dirname + '/fixtures/template-literal-string.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
splitStrings: true,
splitStringsChunkLength: 2
}
).getObfuscatedCode();
assert.match(obfuscatedCode, /^var *test *= *'ab' *\+ *'cd' *\+ *'ef' *\+ *'g';$/);
});
});
describe('Variant #8: object key string literal', () => {
it('should keep original string literal', () => {
const code: string = readFileAsString(__dirname + '/fixtures/object-key-string-literal.js');
@@ -111,7 +146,7 @@ describe('SplitStringTransformer', () => {
});
});
describe('Variant #7: object computed key string literal', () => {
describe('Variant #9: object computed key string literal', () => {
it('should transform string literal to binary expression', () => {
const code: string = readFileAsString(__dirname + '/fixtures/object-computed-key-string-literal.js');