This is partially (HTML/XHTML) covered in sibling bug RT#19802 with a
patch (already needed for HTML-Tree-3.23).
The other problem are trailing new lines. HTML-Tree-4.0 removes
erroneous new lines, so one can use that patch, remove new lines and
these tests will pass.