Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.2k
fix: prevent numeric-only content hashes in filename templates#19897
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
linux-foundation-easyclabot commentedSep 10, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
alexander-akait commentedSep 10, 2025
Please add a test case |
mduclehcm commentedSep 11, 2025
Sorry, but I really don't know how to test this case. It's hard to create a mock module that has a numeric-only content hash. Could you please give me some advice? |
alexander-akait commentedSep 11, 2025
@mduclehcm You can mock some webpack function or create a plugin which generate only numbers |
mduclehcm commentedSep 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've added the unit test! Could you take another look at the PR when you get a chance? |
Problem
When using webpack filename templates with length-limited content hashes (e.g.,
[contenthash:12]), the hash truncation was performed using simple string slicing (hash.slice(0, length)). This could result in truncated hashes that contain only numeric characters, which can cause issues when RealContentHashPlugin try to replace the content hash with real content hash.#14058Root Cause
The
hashLengthfunction inTemplatedPathPlugin.jsused simple string slicing:When a hash like
"123456789101acbdefgh"was truncated to 12 characters, it could produce"123456789101"- a purely numeric string. This creates problems forRealContentHashPluginwhich expects to find and replace these hash patterns.Fix
Use existing
nonNumericOnlyHashutility function that webpack already uses internally: