Skip to content

Commit

Permalink
fix: base64safe regex
Browse files Browse the repository at this point in the history
  • Loading branch information
denisx authored Jun 5, 2024
1 parent 2d6ed3c commit 3b2d3b1
Show file tree
Hide file tree
Showing 2 changed files with 7 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 @@ -77,7 +77,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*(?:safe)?))?(?::(\d+))?\]/gi,
(all, hashType, digestType, maxLength) =>
getHashDigest(content, hashType, digestType, parseInt(maxLength, 10))
);
Expand Down
6 changes: 6 additions & 0 deletions test/interpolateName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ describe("interpolateName()", () => {
"test content",
"modal.lHP90NiApDwht3eNNIch.css",
],
[
"/lib/components/modal/modal.css",
"[name].[md5:contenthash:base64safe:20].[ext]",
"test content",
"modal.8osQznuT8jOAwdzg_nek.css",
],
// Should not interpret without `hash` or `contenthash`
[
"/lib/components/modal/modal.css",
Expand Down

0 comments on commit 3b2d3b1

Please sign in to comment.