summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2022-05-30 14:15:19 +0200
committerStefan Behnel <stefan_ml@behnel.de>2022-05-30 14:15:19 +0200
commitd3f77e678a8394559331d27257714e8aa4b082f2 (patch)
treeeb0e6cffe7bc0794ffc2b2e080a9007531554c40
parent7f7f226656e89a67f02e48d0f744cdd64e959dac (diff)
downloadpython-lxml-d3f77e678a8394559331d27257714e8aa4b082f2.tar.gz
Add a test for https://bugs.launchpad.net/lxml/+bug/1965070 leaving out the actual failure case.
-rw-r--r--src/lxml/tests/test_htmlparser.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lxml/tests/test_htmlparser.py b/src/lxml/tests/test_htmlparser.py
index 4460c1d4..acbde421 100644
--- a/src/lxml/tests/test_htmlparser.py
+++ b/src/lxml/tests/test_htmlparser.py
@@ -653,6 +653,31 @@ class HtmlParserTestCase(HelperTestCase):
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://www.w3.org/1999/xhtml"></html>'
+ )
+ root = html.fromstring(xhtml)
+ print(root.attrib)
+ result = etree.tostring(root)
+ self.assertEqual(result, b'<html xmlns="http://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://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
+ b'<html xmlns="http://www.w3.org/1999/xhtml"></html>'
+ )
+ root = html.fromstring(xhtml)
+ print(root.attrib)
+ result = etree.tostring(root)
+ self.assertEqual(result, b'<html xmlns="http://www.w3.org/1999/xhtml"/>')
+ """
+
def test_suite():
suite = unittest.TestSuite()