Skip to content

Commit 9f8a7c5

Browse files
committed
fix: when using the integrity option, leaves the original attributes in the script tag as is
1 parent 72bd2c3 commit 9f8a7c5

9 files changed

Lines changed: 52 additions & 2 deletions

File tree

CHANGELOG.md

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

3+
## 3.17.1 (2024-08-01)
4+
5+
- fix: when using the integrity option, leaves the original attributes in the script tag as is
6+
37
## 3.17.0 (2024-07-23)
48

59
- feat: add support the `?inline` query for styles imported in JavaScript:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-bundler-webpack-plugin",
3-
"version": "3.17.0",
3+
"version": "3.17.1",
44
"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.",
55
"keywords": [
66
"html",

src/Plugin/Collection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,8 @@ class Collection {
10281028

10291029
let attrsStr = '';
10301030
for (const attrName in attrs) {
1031-
attrsStr += ` ${attrName}="${attrs[attrName]}"`;
1031+
let value = attrs[attrName];
1032+
attrsStr += value == null ? ` ${attrName}` : ` ${attrName}="${value}"`;
10321033
}
10331034

10341035
output += content.slice(pos, startPos) + `<${tag}${attrsStr}>`;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Test</title>
5+
<script async src="main.js" integrity="sha384-E4IoJ3Xutt/6tUVDjvtPwDTTlCfU5oG199UoqWShFCNx6mb4tdpcPLu7sLzNc8Pe" crossorigin="anonymous"></script>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
</body>
10+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(">> main");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Test</title>
5+
<script async src="./main.js"></script>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
</body>
10+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('>> main');
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const path = require('path');
2+
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');
3+
4+
module.exports = {
5+
mode: 'production',
6+
7+
output: {
8+
path: path.join(__dirname, 'dist/'),
9+
crossOriginLoading: 'anonymous', // required for test Subresource Integrity
10+
},
11+
12+
plugins: [
13+
new HtmlBundlerPlugin({
14+
entry: {
15+
index: './src/index.html',
16+
},
17+
integrity: 'auto',
18+
}),
19+
],
20+
};

test/integration.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ describe('integrity, common use cases', () => {
468468
test('script, link, publicPath="auto"', () => compareFiles('integrity-publicPath-auto'));
469469
test('script, link, publicPath=""', () => compareFiles('integrity-publicPath-empty'));
470470
test('script, link, publicPath="/"', () => compareFiles('integrity-publicPath-root'));
471+
472+
473+
test('script async, prod', () => compareFiles('integrity-script-async-prod'));
471474

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

0 commit comments

Comments
 (0)