Skip to content

Commit

Permalink
feat: generate more collision resistant localIdentHash'es:
Browse files Browse the repository at this point in the history
Review fixes
  • Loading branch information
subzey committed Oct 7, 2021
1 parent aba706d commit 725e4a5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function defaultGetLocalIdent(
) {
let relativeMatchResource = "";

const { context } = options;
const { context, hashSalt } = options;
const { resourcePath } = loaderContext;

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

if (hashSalt) {
hash.update(hashSalt);
Expand All @@ -376,9 +375,12 @@ function defaultGetLocalIdent(
hash.update(options.content);

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

Expand Down

0 comments on commit 725e4a5

Please sign in to comment.