瀏覽代碼

Fixed wrong name of obfuscated files when input directory path is the `.` symbol
https://github.com/javascript-obfuscator/javascript-obfuscator/issues/816

sanex 4 年之前
父節點
當前提交
576c50e755

+ 4 - 0
CHANGELOG.md

@@ -1,5 +1,9 @@
 Change Log
 
+v2.9.3
+---
+* **CLI**: Fixed wrong name of obfuscated files when input directory path is the `.` symbol. https://github.com/javascript-obfuscator/javascript-obfuscator/issues/816
+
 v2.9.2
 ---
 * Ignore object expressions as body of arrow function expression when `transformObjectKeys` option is enabled. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/813

File diff suppressed because it is too large
+ 0 - 0
dist/index.browser.js


File diff suppressed because it is too large
+ 0 - 0
dist/index.cli.js


File diff suppressed because it is too large
+ 0 - 0
dist/index.js


+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "javascript-obfuscator",
-  "version": "2.9.2",
+  "version": "2.9.3",
   "description": "JavaScript obfuscator",
   "keywords": [
     "obfuscator",

+ 5 - 1
src/cli/utils/ObfuscatedCodeWriter.ts

@@ -60,7 +60,11 @@ export class ObfuscatedCodeWriter {
 
         if (isDirectoryRawInputPath) {
             if (isDirectoryRawOutputPath) {
-                const baseOutputPath: string = normalizedFilePath.replace(this.inputPath, '');
+                const parsedNormalizedFilePath: path.ParsedPath = path.parse(normalizedFilePath);
+                const baseOutputPath: string = path.join(
+                    parsedNormalizedFilePath.dir.replace(this.inputPath, ''),
+                    parsedNormalizedFilePath.base
+                );
 
                 return path.join(normalizedRawOutputPath, baseOutputPath);
             } else {

+ 54 - 0
test/unit-tests/cli/utils/ObfuscatedCodeWriter.spec.ts

@@ -197,6 +197,60 @@ describe('ObfuscatedCodeWriter', () => {
                     assert.equal(outputCodePath, expectedOutputCodePath);
                 });
             });
+
+            describe('Variant #5: input directory name with dot only', () => {
+                const inputPath: string = path.join('test-input.js');
+                const rawInputPath: string = path.join('.');
+                const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
+                const expectedOutputCodePath: string = path.join(
+                    tmpDirectoryPath,
+                    'output',
+                    'test-input.js'
+                );
+
+                let outputCodePath: string;
+
+                before(() => {
+                    const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
+                        rawInputPath,
+                        {
+                            output: rawOutputPath
+                        }
+                    );
+                    outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath);
+                });
+
+                it('should return output path that contains raw output path and actual file input path', () => {
+                    assert.equal(outputCodePath, expectedOutputCodePath);
+                });
+            });
+
+            describe('Variant #6: input directory name with dot and slash only', () => {
+                const inputPath: string = path.join('test-input.js');
+                const rawInputPath: string = path.join('./');
+                const rawOutputPath: string = path.join(tmpDirectoryPath, 'output');
+                const expectedOutputCodePath: string = path.join(
+                    tmpDirectoryPath,
+                    'output',
+                    'test-input.js'
+                );
+
+                let outputCodePath: string;
+
+                before(() => {
+                    const obfuscatedCodeWriter: ObfuscatedCodeWriter = new ObfuscatedCodeWriter(
+                        rawInputPath,
+                        {
+                            output: rawOutputPath
+                        }
+                    );
+                    outputCodePath = obfuscatedCodeWriter.getOutputCodePath(inputPath);
+                });
+
+                it('should return output path that contains raw output path and actual file input path', () => {
+                    assert.equal(outputCodePath, expectedOutputCodePath);
+                });
+            });
         });
 
         describe('Variant #5: Win32 environment', () => {

Some files were not shown because too many files changed in this diff