hickory icon indicating copy to clipboard operation
hickory copied to clipboard

Failed for handling entity reference HTML code

Open conao3 opened this issue 3 months ago • 1 comments

When parsing HTML using hickory, converting it to hiccup, and then converting it back to HTML, the entity reference for & is processed twice, resulting in inconsistent output. Is this behavior intended? In JavaScript, conversion is never performed twice, and the result remains consistent.

hickory/hiccup behaviour

(-> "<div>a&amp;b</div>"
    hickory.core/parse-fragment
    first
    hickory.core/as-hiccup
    hiccup2.core/html
    str)
;;=> "<div>a&amp;amp;b</div>"

javascript

const div = document.createElement('div')
div.innerHTML = "<div>a&amp;b</div>"
> '<div>a&amp;b</div>'

div.innerHTML
> '<div>a&amp;b</div>'

div.textContent
> 'a&b'

expected

(-> "<div>a&amp;b</div>"
    hickory.core/parse-fragment
    first
    hickory.core/as-hiccup
    hiccup2.core/html
    str)
;;=> "<div>a&amp;b</div>"

conao3 avatar Sep 09 '25 09:09 conao3