Browse Source

Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/590

sanex3339 5 năm trước cách đây
mục cha
commit
75c2a7b5d6

+ 4 - 0
CHANGELOG.md

@@ -1,5 +1,9 @@
 Change Log
 
+v0.27.4
+---
+* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/590
+
 v0.27.3
 ---
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/593

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/index.browser.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/index.cli.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/index.js


+ 3 - 3
package.json

@@ -1,6 +1,6 @@
 {
   "name": "javascript-obfuscator",
-  "version": "0.27.3",
+  "version": "0.27.4",
   "description": "JavaScript obfuscator",
   "keywords": [
     "obfuscator",
@@ -51,7 +51,7 @@
     "@types/eslint-scope": "3.7.0",
     "@types/estraverse": "0.0.6",
     "@types/estree": "0.0.44",
-    "@types/md5": "2.1.33",
+    "@types/md5": "2.2.0",
     "@types/mkdirp": "1.0.0",
     "@types/mocha": "7.0.2",
     "@types/multimatch": "4.0.0",
@@ -66,7 +66,7 @@
     "coveralls": "3.0.11",
     "eslint": "6.8.0",
     "eslint-plugin-import": "2.20.2",
-    "eslint-plugin-jsdoc": "22.1.0",
+    "eslint-plugin-jsdoc": "23.0.0",
     "eslint-plugin-no-null": "1.0.2",
     "eslint-plugin-prefer-arrow": "1.2.0",
     "eslint-plugin-unicorn": "18.0.1",

+ 4 - 0
src/JavaScriptObfuscator.ts

@@ -142,6 +142,10 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
      * @returns {IObfuscatedCode}
      */
     public obfuscate (sourceCode: string): IObfuscatedCode {
+        if (typeof sourceCode !== 'string') {
+            sourceCode = '';
+        }
+
         const timeStart: number = Date.now();
         this.logger.info(LoggingMessage.Version, Utils.buildVersionMessage(process.env.VERSION, process.env.BUILD_TIMESTAMP));
         this.logger.info(LoggingMessage.ObfuscationStarted);

+ 0 - 0
test/fixtures/directory-obfuscation-error/foo-obfuscated.js


+ 40 - 24
test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts

@@ -47,39 +47,55 @@ describe('JavaScriptObfuscator', () => {
             });
         });
 
-        describe('empty source code', () => {
-            let obfuscatedCode: string;
+        describe('Empty or invalid source code', () => {
+            describe('empty source code', () => {
+                let obfuscatedCode: string;
 
-            beforeEach(() => {
-                const code: string = readFileAsString(__dirname + '/fixtures/empty-input.js');
+                beforeEach(() => {
+                    const code: string = readFileAsString(__dirname + '/fixtures/empty-input.js');
 
-                obfuscatedCode = JavaScriptObfuscator.obfuscate(
-                    code,
-                ).getObfuscatedCode();
-            });
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        code,
+                    ).getObfuscatedCode();
+                });
 
-            it('should return an empty obfuscated code', () => {
-                assert.isNotOk(obfuscatedCode);
+                it('should return an empty obfuscated code', () => {
+                    assert.isNotOk(obfuscatedCode);
+                });
             });
-        });
 
-        describe('empty source code with comments', () => {
-            let obfuscatedCode: string;
+            describe('empty source code with comments', () => {
+                let obfuscatedCode: string;
 
-            beforeEach(() => {
-                const code: string = readFileAsString(__dirname + '/fixtures/comments-only.js');
+                beforeEach(() => {
+                    const code: string = readFileAsString(__dirname + '/fixtures/comments-only.js');
 
-                obfuscatedCode = JavaScriptObfuscator.obfuscate(
-                    code,
-                    {
-                        controlFlowFlattening: true,
-                        deadCodeInjection: true
-                    }
-                ).getObfuscatedCode();
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        code,
+                        {
+                            controlFlowFlattening: true,
+                            deadCodeInjection: true
+                        }
+                    ).getObfuscatedCode();
+                });
+
+                it('should return an empty obfuscated code', () => {
+                    assert.isNotOk(obfuscatedCode);
+                });
             });
 
-            it('should return an empty obfuscated code', () => {
-                assert.isNotOk(obfuscatedCode);
+            describe('invalid source code type', () => {
+                let obfuscatedCode: string;
+
+                beforeEach(() => {
+                    obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                        1 as unknown as string
+                    ).getObfuscatedCode();
+                });
+
+                it('should return an empty obfuscated code', () => {
+                    assert.isNotOk(obfuscatedCode);
+                });
             });
         });
 

+ 8 - 8
yarn.lock

@@ -328,10 +328,10 @@
   resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339"
   integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==
 
-"@types/md5@2.1.33":
-  version "2.1.33"
-  resolved "https://registry.yarnpkg.com/@types/md5/-/md5-2.1.33.tgz#8c8dba30df4ad0e92296424f08c4898dd808e8df"
-  integrity sha512-8+X960EtKLoSblhauxLKy3zzotagjoj3Jt1Tx9oaxUdZEPIBl+mkrUz6PNKpzJgkrKSN9YgkWTA29c0KnLshmA==
+"@types/md5@2.2.0":
+  version "2.2.0"
+  resolved "https://registry.yarnpkg.com/@types/md5/-/md5-2.2.0.tgz#cd82e16b95973f94bb03dee40c5b6be4a7fb7fb4"
+  integrity sha512-JN8OVL/wiDlCWTPzplsgMPu0uE9Q6blwp68rYsfk2G8aokRUQ8XD9MEhZwihfAiQvoyE+m31m6i3GFXwYWomKQ==
   dependencies:
     "@types/node" "*"
 
@@ -1866,10 +1866,10 @@ [email protected]:
     read-pkg-up "^2.0.0"
     resolve "^1.12.0"
 
-eslint-plugin-jsdoc@22.1.0:
-  version "22.1.0"
-  resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-22.1.0.tgz#dadfa62653fc0d87f900d810307f5ed07ef6ecd5"
-  integrity sha512-54NdbICM7KrxsGUqQsev9aIMqPXyvyBx2218Qcm0TQ16P9CtBI+YY4hayJR6adrxlq4Ej0JLpgfUXWaQVFqmQg==
+eslint-plugin-jsdoc@23.0.0:
+  version "23.0.0"
+  resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-23.0.0.tgz#f80dca482fc9d93a9e30b3ead70b88dee261caa3"
+  integrity sha512-zj5ZephjKkFU/J9hEw3RcjwpuywChvwNMgHs2DTgOuKarpJ65SJU3JGgx/K4y9l8iFw0ysrk6NlAKDX88ZwZdw==
   dependencies:
     comment-parser "^0.7.2"
     debug "^4.1.1"

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác