Skip to content

Commit 5a6a614

Browse files
committed
fix: #258
1 parent 7fa5002 commit 5a6a614

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/nodes/html.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,7 @@ export default class HTMLElement extends Node {
718718
this.rawAttrs = Object.keys(attrs)
719719
.map((name) => {
720720
const val = this.quoteAttribute(attrs[name]);
721-
if (val === undefined || val === 'null') {
722-
return name;
723-
}
721+
if (val === 'null' || val === '""') return name;
724722
return `${name}=${val}`;
725723
})
726724
.join(' ');

test/tests/issues/258.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { parse } = require('@test/test-target');
2+
3+
describe('issue 258', function () {
4+
it('removeAttribute makes boolean attributes render incorrectly.', function () {
5+
const inputEl = parse('<input>').firstChild
6+
7+
inputEl.setAttribute('checked', '');
8+
inputEl.setAttribute('a', '');
9+
inputEl.toString().should.eql('<input checked a>');
10+
11+
inputEl.removeAttribute('a');
12+
inputEl.toString().should.eql('<input checked>');
13+
console.log(inputEl.toString()); // => <input checked=""> INCORRECT
14+
// div.innerText.should.eql(`Hello World`);
15+
});
16+
});

0 commit comments

Comments
 (0)