Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions dist/index.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.27.3",
"version": "0.27.4",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/JavaScriptObfuscator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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" "*"

Expand Down Expand Up @@ -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"
Expand Down