Skip to content

bpo-36407: Fix writing indentations of CDATA section (xml.dom.minidom) #12514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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 testCDATAWriting(self):
doc = Document()
root = doc.createElement('root')
doc.appendChild(root)
node = doc.createElement('node')
root.appendChild(node)
data = doc.createCDATASection('</data>')
node.appendChild(data)

doc1 = parseString(doc.toxml())
val1 = doc1.getElementsByTagName('node')[0].firstChild.nodeValue
doc2 = parseString(doc.toprettyxml())
val2 = doc2.getElementsByTagName('node')[0].firstChild.nodeValue

self.confirm(val1 == val2)

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 @@
Fixed wrong indentation writing for CDATA section in xml.dom.minidom