Skip to content

Commit 3b59bd2

Browse files
committed
feat: generate more collision resistant localIdentHash'es
1 parent b29d389 commit 3b59bd2

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/utils.js

+21-12
Original file line numberDiff line numberDiff line change
@@ -359,21 +359,30 @@ function defaultGetLocalIdent(
359359
);
360360
}
361361

362-
// eslint-disable-next-line no-underscore-dangle
363-
const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
364-
const { hashSalt } = options;
362+
let localIdentHash = "";
363+
for (
364+
const tierSalt = Uint32Array.of(0);
365+
localIdentHash.length < hashDigestLength;
366+
tierSalt[0]++
367+
) {
368+
// eslint-disable-next-line no-underscore-dangle
369+
const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
370+
const { hashSalt } = options;
365371

366-
if (hashSalt) {
367-
hash.update(hashSalt);
368-
}
372+
if (hashSalt) {
373+
hash.update(hashSalt);
374+
}
375+
376+
hash.update(tierSalt);
369377

370-
hash.update(options.content);
378+
hash.update(options.content);
371379

372-
const localIdentHash = hash
373-
.digest(hashDigest)
374-
.slice(0, hashDigestLength)
375-
.replace(/[/+]/g, "_")
376-
.replace(/^\d/g, "_");
380+
localIdentHash = (localIdentHash + hash.digest(hashDigest))
381+
.replace(/^\d+/, "")
382+
.slice(0, hashDigestLength)
383+
.replace(/\+/g, "-")
384+
.replace(/\//g, "_");
385+
}
377386

378387
// TODO need improve on webpack side, we should allow to pass hash/contentHash without chunk property, also `data` for `getPath` should be looks good without chunk property
379388
const ext = path.extname(resourcePath);

0 commit comments

Comments
 (0)