File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -653,6 +653,31 @@ def test_boolean_attribute_xml_adds_empty_string(self):
653
653
self .assertEqual (self .etree .tostring (html .fragment_fromstring (fragment )),
654
654
_bytes ('<tag attribute=""/>' ))
655
655
656
+ def test_xhtml_as_html_as_xml (self ):
657
+ # parse XHTML as HTML, serialise as XML
658
+ # See https://bugs.launchpad.net/lxml/+bug/1965070
659
+ xhtml = (
660
+ b'<?xml version="1.0" encoding="UTF-8"?>'
661
+ b'<html xmlns="http://www.w3.org/1999/xhtml"></html>'
662
+ )
663
+ root = html .fromstring (xhtml )
664
+ print (root .attrib )
665
+ result = etree .tostring (root )
666
+ self .assertEqual (result , b'<html xmlns="http://www.w3.org/1999/xhtml"/>' )
667
+
668
+ # Adding an XHTML doctype makes libxml2 add the namespace, which wasn't parsed as such by the HTML parser.
669
+ """
670
+ xhtml = (
671
+ b'<?xml version="1.0" encoding="UTF-8"?>'
672
+ b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
673
+ b'<html xmlns="http://www.w3.org/1999/xhtml"></html>'
674
+ )
675
+ root = html.fromstring(xhtml)
676
+ print(root.attrib)
677
+ result = etree.tostring(root)
678
+ self.assertEqual(result, b'<html xmlns="http://www.w3.org/1999/xhtml"/>')
679
+ """
680
+
656
681
657
682
def test_suite ():
658
683
suite = unittest .TestSuite ()
You can’t perform that action at this time.
0 commit comments