Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add digestType 'base64-safe' #259

Merged
merged 7 commits into from
Jun 4, 2024

Conversation

denisx
Copy link
Contributor

@denisx denisx commented May 30, 2024

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

To simplify migration from v2 and getting "clean" css classnames, digestType with base64-safe don't contain /, + and = symbols.

Breaking Changes

No

@denisx denisx marked this pull request as ready for review May 30, 2024 18:18
@@ -76,17 +76,19 @@ The following tokens are replaced in the `name` parameter:
- `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the `xxhash64` hash)
- `[<hashType>:contenthash:<digestType>:<length>]` optionally one can configure
- other `hashType`s, i. e. `xxhash64`, `sha1`, `md4` (wasm version), `native-md4` (`crypto` module version), `md5`, `sha256`, `sha512`
- other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
- other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`, `base64safe`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to base64safe (without -), because regexp in interpolateName can be used in many place and I don't want to change it

return hash.digest(digestType || "hex").substr(0, maxLength);
return encodeBufferToBase(
hash.digest(),
digestType === "base64safe" ? 64 : digestType.substr(4),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also use a table to achieve higher entropy, removing characters can create conflicts, i.e. 3ZWmHo0=hPMWE2rZeN_oHB6 and 3ZWmHo0hPMWE2rZe=N_oHB6 will be same after removing characters, this is bad

@alexander-akait alexander-akait merged commit af15793 into webpack:master Jun 4, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants