Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removeAttribute makes boolean attributes render incorrectly. #258

Closed
allain opened this issue Nov 24, 2023 · 0 comments
Closed

removeAttribute makes boolean attributes render incorrectly. #258

allain opened this issue Nov 24, 2023 · 0 comments
Labels

Comments

@allain
Copy link

allain commented Nov 24, 2023

It appears that removing an attribute causes boolean attributes to be rendered incorrectly:

const {parse} = require("node-html-parser")
const inputEl = parse('<input>').firstChild

inputEl.setAttribute('checked', '')
inputEl.setAttribute('a', '')
console.log(inputEl.toString()) // => <input checked a> CORRECT

inputEl.removeAttribute('a')
console.log(inputEl.toString()) // => <input checked=""> INCORRECT

If it helps narrow it down, the bug does not happen if the boolean attribute was not added using setAttribute:

const {parse} = require("node-html-parser")
const inputEl = parse('<input checked>').firstChild

inputEl.setAttribute('a', '')
console.log(inputEl.toString()) // => <input checked a> CORRECT

inputEl.removeAttribute('a')
console.log(inputEl.toString()) // => <input checked> CORRECT
@taoqf taoqf added the bug label Dec 21, 2023
@taoqf taoqf closed this as completed in 5a6a614 Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants