Skip to content

Commit

Permalink
fix: when using the integrity option, leaves the original attributes …
Browse files Browse the repository at this point in the history
…in the script tag as is
  • Loading branch information
webdiscus committed Aug 1, 2024
1 parent 72bd2c3 commit 9f8a7c5
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## 3.17.1 (2024-08-01)

- fix: when using the integrity option, leaves the original attributes in the script tag as is

## 3.17.0 (2024-07-23)

- feat: add support the `?inline` query for styles imported in JavaScript:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-bundler-webpack-plugin",
"version": "3.17.0",
"version": "3.17.1",
"description": "HTML bundler plugin for webpack handles a template as an entry point, extracts CSS and JS from their sources referenced in HTML, supports template engines like Eta, EJS, Handlebars, Nunjucks.",
"keywords": [
"html",
Expand Down
3 changes: 2 additions & 1 deletion src/Plugin/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,8 @@ class Collection {

let attrsStr = '';
for (const attrName in attrs) {
attrsStr += ` ${attrName}="${attrs[attrName]}"`;
let value = attrs[attrName];
attrsStr += value == null ? ` ${attrName}` : ` ${attrName}="${value}"`;
}

output += content.slice(pos, startPos) + `<${tag}${attrsStr}>`;
Expand Down
10 changes: 10 additions & 0 deletions test/cases/integrity-script-async-prod/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script async src="main.js" integrity="sha384-E4IoJ3Xutt/6tUVDjvtPwDTTlCfU5oG199UoqWShFCNx6mb4tdpcPLu7sLzNc8Pe" crossorigin="anonymous"></script>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
1 change: 1 addition & 0 deletions test/cases/integrity-script-async-prod/expected/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(">> main");
10 changes: 10 additions & 0 deletions test/cases/integrity-script-async-prod/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script async src="./main.js"></script>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
1 change: 1 addition & 0 deletions test/cases/integrity-script-async-prod/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('>> main');
20 changes: 20 additions & 0 deletions test/cases/integrity-script-async-prod/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const path = require('path');
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');

module.exports = {
mode: 'production',

output: {
path: path.join(__dirname, 'dist/'),
crossOriginLoading: 'anonymous', // required for test Subresource Integrity
},

plugins: [
new HtmlBundlerPlugin({
entry: {
index: './src/index.html',
},
integrity: 'auto',
}),
],
};
3 changes: 3 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ describe('integrity, common use cases', () => {
test('script, link, publicPath="auto"', () => compareFiles('integrity-publicPath-auto'));
test('script, link, publicPath=""', () => compareFiles('integrity-publicPath-empty'));
test('script, link, publicPath="/"', () => compareFiles('integrity-publicPath-root'));


test('script async, prod', () => compareFiles('integrity-script-async-prod'));

test('split chunks', () => compareFiles('integrity-split-chunks'));
test('import css', () => compareFiles('integrity-import-css-in-js'));
Expand Down

0 comments on commit 9f8a7c5

Please sign in to comment.