Skip to content

Commit 61459d6

Browse files
committed
bug #1349 Fix issue between Encore.enableIntegrityHashes() and filenames with a query-string (Kocal)
This PR was merged into the main branch. Discussion ---------- Fix issue between `Encore.enableIntegrityHashes()` and filenames with a query-string | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update CHANGELOG.md file --> | Deprecations? | no <!-- please update CHANGELOG.md file --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Features and deprecations must be submitted against the latest branch. - For new features, provide some code snippets to help understand usage. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility. --> When working on symfony/webpack-encore-bundle#237, I haven't able to see integrity hashes added on `<link>` tags, because my project uses query-string in generated filenames, but the bundle was not able to get those integrity hashes (because the `entrypoints.json` file contained `"/build/sentry.js": "sha384-hash"` instead of `"/build/sentry.js?v=b86ff72e": "sha384-hash"`) Commits ------- c965684 Fix integrity hashes with query string, use the original assets name in "integrity" map
2 parents ce54d41 + c965684 commit 61459d6

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 5.0.1
4+
5+
* #1349 Fix issue between `Encore.enableIntegrityHashes()` and filenames with a query-string (@Kocal)
6+
37
## 5.0.0
48

59
This is a new major version that contains several backwards-compatibility breaks.

lib/webpack/entry-points-plugin.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ class EntryPointsPlugin {
9595
for (const entryName in manifest.entrypoints) {
9696
for (const fileType in manifest.entrypoints[entryName]) {
9797
for (const asset of manifest.entrypoints[entryName][fileType]) {
98+
if (asset in manifest.integrity) {
99+
continue;
100+
}
101+
98102
// Drop query string if any
99103
const assetNormalized = asset.includes('?') ? asset.split('?')[0] : asset;
100-
101104
if (assetNormalized in manifest.integrity) {
102105
continue;
103106
}
@@ -118,7 +121,7 @@ class EntryPointsPlugin {
118121
fileHashes.push(`${algorithm}-${hash.digest('base64')}`);
119122
}
120123

121-
manifest.integrity[assetNormalized] = fileHashes.join(' ');
124+
manifest.integrity[asset] = fileHashes.join(' ');
122125
}
123126
}
124127
}

test/functional.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,11 +3138,14 @@ module.exports = {
31383138

31393139
testSetup.runWebpack(config, (webpackAssert) => {
31403140
const integrityData = getIntegrityData(config);
3141-
const expectedFilesWithHashes = [
3142-
'/build/runtime.js',
3143-
'/build/main.js',
3144-
'/build/styles.css',
3145-
];
3141+
const expectedFilesWithHashes = Object.keys(integrityData).filter(file => {
3142+
if (!/\?v=[a-z0-9]{16}$/.test(file)) {
3143+
return false;
3144+
}
3145+
return file.startsWith('/build/runtime.js?v=')
3146+
|| file.startsWith('/build/main.js?v=')
3147+
|| file.startsWith('/build/styles.css?v=');
3148+
});
31463149

31473150
expectedFilesWithHashes.forEach((file) => {
31483151
expect(integrityData[file]).to.contain('sha384-');

0 commit comments

Comments
 (0)