Skip to content

Commit 725e4a5

Browse files
committed
feat: generate more collision resistant localIdentHash'es:
Review fixes
1 parent aba706d commit 725e4a5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/utils.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ function defaultGetLocalIdent(
319319
) {
320320
let relativeMatchResource = "";
321321

322-
const { context } = options;
322+
const { context, hashSalt } = options;
323323
const { resourcePath } = loaderContext;
324324

325325
// eslint-disable-next-line no-underscore-dangle
@@ -363,7 +363,6 @@ function defaultGetLocalIdent(
363363
for (let tier = 0; localIdentHash.length < hashDigestLength; tier++) {
364364
// eslint-disable-next-line no-underscore-dangle
365365
const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
366-
const { hashSalt } = options;
367366

368367
if (hashSalt) {
369368
hash.update(hashSalt);
@@ -376,9 +375,12 @@ function defaultGetLocalIdent(
376375
hash.update(options.content);
377376

378377
localIdentHash = (localIdentHash + hash.digest(hashDigest))
378+
// Remove all leading digits
379379
.replace(/^\d+/, "")
380+
// Replace all slashes with underscores (same as in base64url)
380381
.replace(/\//g, "_")
381-
.replace(/\W+/g, "")
382+
// Remove everything that is not an alphanumeric or underscore
383+
.replace(/[^A-Za-z0-9_]+/g, "")
382384
.slice(0, hashDigestLength);
383385
}
384386

0 commit comments

Comments
 (0)