Skip to content

Commit 67499ff

Browse files
authoredOct 20, 2017
Merge pull request #94 from rsms/fix-hash-regex
Fixes "[hash]" token regex in interpolateString to capture any hash algorithm name
2 parents 5854d87 + 3cd3889 commit 67499ff

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎lib/interpolateName.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function interpolateName(loaderContext, name, options) {
6868
// Match hash template
6969
url = url
7070
.replace(
71-
/\[(?:(\w+):)?hash(?::([a-z]+\d*))?(?::(\d+))?\]/ig,
71+
/\[(?:([^:]+):)?hash(?::([a-z]+\d*))?(?::(\d+))?\]/ig,
7272
(all, hashType, digestType, maxLength) => getHashDigest(content, hashType, digestType, parseInt(maxLength, 10))
7373
)
7474
.replace(

‎test/interpolateName.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ describe("interpolateName()", () => {
3838
});
3939
});
4040

41+
[ "sha1fakename",
42+
"9dxfakename",
43+
"RSA-SHA256-fakename",
44+
"ecdsa-with-SHA1-fakename",
45+
"tls1.1-sha512-fakename",
46+
].forEach(hashName => {
47+
it("should pick hash algorithm by name " + hashName, () => {
48+
assert.throws(
49+
() => {
50+
const interpolatedName = loaderUtils.interpolateName(
51+
{ }, "[" + hashName + ":hash:base64:10]", {content:"a"}
52+
);
53+
// if for any reason the system we're running on has a hash
54+
// algorithm matching any of our bogus names, at least make sure
55+
// the output is not the unmodified name:
56+
assert(interpolatedName[0] !== '[');
57+
},
58+
/digest method not supported/i
59+
);
60+
});
61+
});
62+
63+
4164
run([
4265
[[{}, "", { content: "test string" }], "6f8db599de986fab7a21625b7916589c.bin", "should interpolate default tokens"],
4366
[[{}, "[hash:base64]", { content: "test string" }], "2sm1pVmS8xuGJLCdWpJoRL", "should interpolate [hash] token with options"],

0 commit comments

Comments
 (0)
Please sign in to comment.