From 3528fd961c6be08e587fd577e2d9996e27e436f4 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Thu, 27 Dec 2018 15:21:34 +0300 Subject: [PATCH] fix(interpolateName): don't interpolated `hashType` without `hash` or `contenthash` (#140) --- lib/interpolateName.js | 2 +- test/interpolateName.test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/interpolateName.js b/lib/interpolateName.js index cfe2ec0..d1fa661 100644 --- a/lib/interpolateName.js +++ b/lib/interpolateName.js @@ -91,7 +91,7 @@ function interpolateName(loaderContext, name, options) { // `hash` and `contenthash` are same in `loader-utils` context // let's keep `hash` for backward compatibility .replace( - /\[(?:([^:\]]+):)?(?:hash||contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, + /\[(?:([^:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, (all, hashType, digestType, maxLength) => getHashDigest(content, hashType, digestType, parseInt(maxLength, 10)) ) diff --git a/test/interpolateName.test.js b/test/interpolateName.test.js index 05b59f7..e57443a 100644 --- a/test/interpolateName.test.js +++ b/test/interpolateName.test.js @@ -124,6 +124,13 @@ describe('interpolateName()', () => { 'test content', 'modal.1n8osQznuT8jOAwdzg_n.css', ], + // Should not interpret without `hash` or `contenthash` + [ + '/lib/components/modal/modal.css', + '[name].[md5::base64:20].[ext]', + 'test content', + 'modal.[md5::base64:20].css', + ], ].forEach((test) => { it('should interpolate ' + test[0] + ' ' + test[1], () => { const interpolatedName = loaderUtils.interpolateName(