Skip to content

Commit

Permalink
Do not add integrity attributes if the entire plugin is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
sersorrel committed May 11, 2021
1 parent 597e4d1 commit bbc072a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugin.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ describe('CspHtmlWebpackPlugin', () => {
webpackCompile(config, (csps, selectors) => {
expect(csps['index.html']).toBeUndefined();
expect(selectors['index.html']('meta').length).toEqual(1);
expect(selectors['index.html']('[integrity]').length).toEqual(0);
done();
});
});
Expand All @@ -896,6 +897,7 @@ describe('CspHtmlWebpackPlugin', () => {
webpackCompile(config, (csps, selectors) => {
expect(csps['index.html']).toBeUndefined();
expect(selectors['index.html']('meta').length).toEqual(1);
expect(selectors['index.html']('[integrity]').length).toEqual(0);
done();
});
});
Expand All @@ -922,6 +924,7 @@ describe('CspHtmlWebpackPlugin', () => {
webpackCompile(config, (csps, selectors) => {
expect(csps['index.html']).toBeUndefined();
expect(selectors['index.html']('meta').length).toEqual(1);
expect(selectors['index.html']('[integrity]').length).toEqual(0);
done();
});
});
Expand Down Expand Up @@ -957,6 +960,12 @@ describe('CspHtmlWebpackPlugin', () => {
expect(csps['index-disabled.html']).toBeUndefined();
expect(selectors['index-enabled.html']('meta').length).toEqual(2);
expect(selectors['index-disabled.html']('meta').length).toEqual(1);
expect(selectors['index-enabled.html']('[integrity]').length).toEqual(
1
);
expect(selectors['index-disabled.html']('[integrity]').length).toEqual(
0
);
done();
});
});
Expand Down
3 changes: 3 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ class CspHtmlWebpackPlugin {
* @param compileCb
*/
addIntegrityAttributes(compilation, htmlPluginData, compileCb) {
if (!this.isEnabled(htmlPluginData)) {
return compileCb(null, htmlPluginData);
}
if (this.hashEnabled['script-src'] !== false) {
htmlPluginData.assetTags.scripts
.filter((tag) => tag.attributes.src)
Expand Down

0 comments on commit bbc072a

Please sign in to comment.