Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_minidom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,5 +1631,21 @@ def test_toprettyxml_with_attributes_ordered(self):
'<?xml version="1.0" ?>\n'
'<curriculum status="public" company="example"/>\n')

def test_toprettyxml_with_cdata(self):
xml_str = '<?xml version="1.0" ?><root><node><![CDATA[</data>]]></node></root>'
doc = parseString(xml_str)
self.assertEqual(doc.toprettyxml(),
'<?xml version="1.0" ?>\n'
'<root>\n'
'\t<node><![CDATA[</data>]]></node>\n'
'</root>\n')

def test_cdata_parsing(self):
xml_str = '<?xml version="1.0" ?><root><node><![CDATA[</data>]]></node></root>'
dom1 = parseString(xml_str)
self.checkWholeText(dom1.getElementsByTagName('node')[0].firstChild, '</data>')
dom2 = parseString(dom1.toprettyxml())
self.checkWholeText(dom2.getElementsByTagName('node')[0].firstChild, '</data>')

if __name__ == "__main__":
unittest.main()
3 changes: 2 additions & 1 deletion Lib/xml/dom/minidom.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ def writexml(self, writer, indent="", addindent="", newl=""):
if self.childNodes:
writer.write(">")
if (len(self.childNodes) == 1 and
self.childNodes[0].nodeType == Node.TEXT_NODE):
self.childNodes[0].nodeType in (
Node.TEXT_NODE, Node.CDATA_SECTION_NODE)):
self.childNodes[0].writexml(writer, '', '', '')
else:
writer.write(newl)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed wrong indentation writing for CDATA section in xml.dom.minidom.
Patch by Vladimir Surjaninov.