Skip to content

Commit cb95347

Browse files
committed
Do not add integrity attributes if the entire plugin is disabled
1 parent 597e4d1 commit cb95347

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

plugin.jest.js

+5
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ describe('CspHtmlWebpackPlugin', () => {
872872
webpackCompile(config, (csps, selectors) => {
873873
expect(csps['index.html']).toBeUndefined();
874874
expect(selectors['index.html']('meta').length).toEqual(1);
875+
expect(selectors['index.html']('[integrity]').length).toEqual(0);
875876
done();
876877
});
877878
});
@@ -896,6 +897,7 @@ describe('CspHtmlWebpackPlugin', () => {
896897
webpackCompile(config, (csps, selectors) => {
897898
expect(csps['index.html']).toBeUndefined();
898899
expect(selectors['index.html']('meta').length).toEqual(1);
900+
expect(selectors['index.html']('[integrity]').length).toEqual(0);
899901
done();
900902
});
901903
});
@@ -922,6 +924,7 @@ describe('CspHtmlWebpackPlugin', () => {
922924
webpackCompile(config, (csps, selectors) => {
923925
expect(csps['index.html']).toBeUndefined();
924926
expect(selectors['index.html']('meta').length).toEqual(1);
927+
expect(selectors['index.html']('[integrity]').length).toEqual(0);
925928
done();
926929
});
927930
});
@@ -957,6 +960,8 @@ describe('CspHtmlWebpackPlugin', () => {
957960
expect(csps['index-disabled.html']).toBeUndefined();
958961
expect(selectors['index-enabled.html']('meta').length).toEqual(2);
959962
expect(selectors['index-disabled.html']('meta').length).toEqual(1);
963+
expect(selectors['index-enabled.html']('[integrity]').length).toEqual(1);
964+
expect(selectors['index-disabled.html']('[integrity]').length).toEqual(0);
960965
done();
961966
});
962967
});

plugin.js

+3
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ class CspHtmlWebpackPlugin {
431431
* @param compileCb
432432
*/
433433
addIntegrityAttributes(compilation, htmlPluginData, compileCb) {
434+
if (!this.isEnabled(htmlPluginData)) {
435+
return compileCb(null, htmlPluginData);
436+
}
434437
if (this.hashEnabled['script-src'] !== false) {
435438
htmlPluginData.assetTags.scripts
436439
.filter((tag) => tag.attributes.src)

0 commit comments

Comments
 (0)