Skip to content

Commit f9b60f3

Browse files
committed
fix: preserve attribute quotes immediately before self-closing slash
1 parent d262bc9 commit f9b60f3

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎lib/html/syntax.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8328,7 +8328,18 @@ const printer = (path, writer) => {
83288328
value !== "" &&
83298329
!/[\s"'`=<>]/.test(value)
83308330
) {
8331-
attrString = `${name}=${value}`;
8331+
let nextChar = "";
8332+
if (attr.valueStart !== -1) {
8333+
const quote = _htmlSource[attr.valueStart - 1];
8334+
const attrEnd =
8335+
quote === '"' || quote === "'"
8336+
? attr.valueEnd + 1
8337+
: attr.valueEnd;
8338+
nextChar = _htmlSource[attrEnd];
8339+
}
8340+
if (nextChar !== "/") {
8341+
attrString = `${name}=${value}`;
8342+
}
83328343
}
83338344

83348345
if (attrString !== null) {
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import "./page.html";
2-
3-
it("should safely minify emitted HTML when optimization.minimize is enabled", () => {
4-
// The assertions on the emitted file live in test.config.js (afterExecute),
5-
// this keeps a runnable entry so the chunk (and its `.html`) is produced.
2+
it("should handle minification with cloned and merged attributes", () => {
63
expect(true).toBe(true);
74
});

‎test/configCases/html/minimize-corrupt-tags/page.html‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
<body class="test2" data-bool disabled>
77
<!-- Adoption agency clones -->
88
<b><i><s><u><p>test</p></b></u></s></i>
9+
<!-- Void tag with unquoted attr slash issue -->
10+
<input type="text"/>
11+
<input type="text" />
912
</body>
1013
</html>

‎test/configCases/html/minimize-corrupt-tags/test.config.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,13 @@ module.exports = {
2626
}`
2727
);
2828
}
29+
if (!html.includes('<input type="text"/>')) {
30+
throw new Error(
31+
`Self-closing void tag without space broke. HTML: ${html}`
32+
);
33+
}
34+
if (!html.includes("<input type=text />")) {
35+
throw new Error(`Self-closing void tag with space broke. HTML: ${html}`);
36+
}
2937
}
3038
};

0 commit comments

Comments
 (0)