From b64942854b84ba41c0f75a845d66c88fcaa2cc06 Mon Sep 17 00:00:00 2001 From: Deliaz Date: Thu, 6 Sep 2018 19:06:08 +0700 Subject: [PATCH] Throw error if "from" is an empty string #278 --- src/preProcessPattern.js | 3 +++ tests/index.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/preProcessPattern.js b/src/preProcessPattern.js index ec7e286d..4ff5ca76 100644 --- a/src/preProcessPattern.js +++ b/src/preProcessPattern.js @@ -14,6 +14,9 @@ export default function preProcessPattern(globalRef, pattern) { pattern = typeof pattern === 'string' ? { from: pattern } : Object.assign({}, pattern); + if (pattern.from === '') { + throw new Error('[copy-webpack-plugin] path "from" cannot be empty string'); + } pattern.to = pattern.to || ''; pattern.context = pattern.context || context; if (!path.isAbsolute(pattern.context)) { diff --git a/tests/index.js b/tests/index.js index bcb8497e..8c65ace5 100644 --- a/tests/index.js +++ b/tests/index.js @@ -227,6 +227,16 @@ describe('apply function', () => { expect(createPluginWithNull).to.throw(Error); }); + + it('throws an error if the "from" path is an empty string', () => { + const createPluginWithNull = () => { + CopyWebpackPlugin({ + from: '' + }); + }; + + expect(createPluginWithNull).to.throw(Error); + }); }); describe('with glob in from', () => { @@ -1434,7 +1444,7 @@ describe('apply function', () => { patterns: [{ from: '.' }] - + }) .then(done) .catch(done);