Skip to content

Commit

Permalink
Add a test for https://bugs.launchpad.net/lxml/+bug/1965070 leaving o…
Browse files Browse the repository at this point in the history
…ut the actual failure case.
  • Loading branch information
scoder committed May 30, 2022
1 parent 7f7f226 commit d3f77e6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lxml/tests/test_htmlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,31 @@ def test_boolean_attribute_xml_adds_empty_string(self):
self.assertEqual(self.etree.tostring(html.fragment_fromstring(fragment)),
_bytes('<tag attribute=""/>'))

def test_xhtml_as_html_as_xml(self):
# parse XHTML as HTML, serialise as XML
# See https://bugs.launchpad.net/lxml/+bug/1965070
xhtml = (
b'<?xml version="1.0" encoding="UTF-8"?>'
b'<html xmlns="http:https://www.w3.org/1999/xhtml"></html>'
)
root = html.fromstring(xhtml)
print(root.attrib)
result = etree.tostring(root)
self.assertEqual(result, b'<html xmlns="http:https://www.w3.org/1999/xhtml"/>')

# Adding an XHTML doctype makes libxml2 add the namespace, which wasn't parsed as such by the HTML parser.
"""
xhtml = (
b'<?xml version="1.0" encoding="UTF-8"?>'
b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
b'<html xmlns="http:https://www.w3.org/1999/xhtml"></html>'
)
root = html.fromstring(xhtml)
print(root.attrib)
result = etree.tostring(root)
self.assertEqual(result, b'<html xmlns="http:https://www.w3.org/1999/xhtml"/>')
"""


def test_suite():
suite = unittest.TestSuite()
Expand Down

0 comments on commit d3f77e6

Please sign in to comment.