mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge pull request #457 from javascript-obfuscator/split-string-template-literal
The `splitStrings` option now affects template literal strings
This commit is contained in:
@@ -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
|
||||
|
||||
Vendored
+3
-3
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
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
+37
-2
@@ -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');
|
||||
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
var test = `abcdefg`;
|
||||
Reference in New Issue
Block a user