From f8a71f4517926e1455ddb756a9166b2a87bfa968 Mon Sep 17 00:00:00 2001 From: Denys Kniazevych Date: Thu, 27 Dec 2018 11:07:41 +0100 Subject: [PATCH] fix: fixed a hash type extracting in interpolateName (#137) --- .gitignore | 1 + lib/interpolateName.js | 2 +- test/interpolateName.test.js | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ba2a97b..428a1df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +.idea node_modules coverage diff --git a/lib/interpolateName.js b/lib/interpolateName.js index 7aa69bc..cfe2ec0 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 20df069..00c912d 100644 --- a/test/interpolateName.test.js +++ b/test/interpolateName.test.js @@ -100,6 +100,12 @@ describe('interpolateName()', () => { 'test content', 'js/filenameWithoutExt.bin', ], + [ + '/lib/components/modal/modal.css', + '[name]__modalTitle___[sha1:hash:hex:4]', + 'test content', + 'modal__modalTitle___1eeb', + ], ].forEach((test) => { it('should interpolate ' + test[0] + ' ' + test[1], () => { const interpolatedName = loaderUtils.interpolateName(