Skip to content

Commit

Permalink
fix: #258
Browse files Browse the repository at this point in the history
  • Loading branch information
taoqf committed Dec 25, 2023
1 parent 7fa5002 commit 5a6a614
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,7 @@ export default class HTMLElement extends Node {
this.rawAttrs = Object.keys(attrs)
.map((name) => {
const val = this.quoteAttribute(attrs[name]);
if (val === undefined || val === 'null') {
return name;
}
if (val === 'null' || val === '""') return name;
return `${name}=${val}`;
})
.join(' ');
Expand Down
16 changes: 16 additions & 0 deletions test/tests/issues/258.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { parse } = require('@test/test-target');

describe('issue 258', function () {
it('removeAttribute makes boolean attributes render incorrectly.', function () {
const inputEl = parse('<input>').firstChild

inputEl.setAttribute('checked', '');
inputEl.setAttribute('a', '');
inputEl.toString().should.eql('<input checked a>');

inputEl.removeAttribute('a');
inputEl.toString().should.eql('<input checked>');
console.log(inputEl.toString()); // => <input checked=""> INCORRECT
// div.innerText.should.eql(`Hello World`);
});
});

0 comments on commit 5a6a614

Please sign in to comment.