Skip to content

Commit

Permalink
fix(interpolateName): don't interpolated hashType without hash or…
Browse files Browse the repository at this point in the history
… `contenthash` (#140)
  • Loading branch information
evilebottnawi authored Dec 27, 2018
1 parent 809b690 commit 3528fd9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/interpolateName.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
Expand Down
7 changes: 7 additions & 0 deletions test/interpolateName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3528fd9

Please sign in to comment.