Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mduclehcm
Copy link

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. #14058

Root Cause

The hashLength function in TemplatedPathPlugin.js used simple string slicing:

// Before: Could produce numeric-only hashes
result = length ? hash.slice(0, length) : hash;

When a hash like "123456789101acbdefgh" was truncated to 12 characters, it could produce "123456789101" - a purely numeric string. This creates problems for RealContentHashPlugin which expects to find and replace these hash patterns.

Fix

Use existing nonNumericOnlyHash utility function that webpack already uses internally:

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Sep 10, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@alexander-akait
Copy link
Member

Please add a test case

@mduclehcm
Copy link
Author

Please add a test case

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
Copy link
Member

@mduclehcm You can mock some webpack function or create a plugin which generate only numbers

@mduclehcm
Copy link
Author

mduclehcm commented Sep 19, 2025

@mduclehcm You can mock some webpack function or create a plugin which generate only numbers

I've added the unit test! Could you take another look at the PR when you get a chance?

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