Skip to content

Commit

Permalink
Merge pull request #94 from rsms/fix-hash-regex
Browse files Browse the repository at this point in the history
Fixes "[hash]" token regex in interpolateString to capture any hash algorithm name
  • Loading branch information
sokra committed Oct 20, 2017
2 parents 5854d87 + 3cd3889 commit 67499ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/interpolateName.js
Expand Up @@ -68,7 +68,7 @@ function interpolateName(loaderContext, name, options) {
// Match hash template
url = url
.replace(
/\[(?:(\w+):)?hash(?::([a-z]+\d*))?(?::(\d+))?\]/ig,
/\[(?:([^:]+):)?hash(?::([a-z]+\d*))?(?::(\d+))?\]/ig,
(all, hashType, digestType, maxLength) => getHashDigest(content, hashType, digestType, parseInt(maxLength, 10))
)
.replace(
Expand Down
23 changes: 23 additions & 0 deletions test/interpolateName.test.js
Expand Up @@ -38,6 +38,29 @@ describe("interpolateName()", () => {
});
});

[ "sha1fakename",
"9dxfakename",
"RSA-SHA256-fakename",
"ecdsa-with-SHA1-fakename",
"tls1.1-sha512-fakename",
].forEach(hashName => {
it("should pick hash algorithm by name " + hashName, () => {
assert.throws(
() => {
const interpolatedName = loaderUtils.interpolateName(
{ }, "[" + hashName + ":hash:base64:10]", {content:"a"}
);
// if for any reason the system we're running on has a hash
// algorithm matching any of our bogus names, at least make sure
// the output is not the unmodified name:
assert(interpolatedName[0] !== '[');
},
/digest method not supported/i
);
});
});


run([
[[{}, "", { content: "test string" }], "6f8db599de986fab7a21625b7916589c.bin", "should interpolate default tokens"],
[[{}, "[hash:base64]", { content: "test string" }], "2sm1pVmS8xuGJLCdWpJoRL", "should interpolate [hash] token with options"],
Expand Down

0 comments on commit 67499ff

Please sign in to comment.