]> granicus.if.org Git - python/commitdiff
#4147: minidom's toprettyxml no longer adds whitespace to text nodes.
authorR David Murray <rdmurray@bitdance.com>
Sat, 1 Oct 2011 20:19:51 +0000 (16:19 -0400)
committerR David Murray <rdmurray@bitdance.com>
Sat, 1 Oct 2011 20:19:51 +0000 (16:19 -0400)
Patch by Dan Kenigsberg.

Lib/test/test_minidom.py
Lib/xml/dom/minidom.py
Misc/ACKS
Misc/NEWS

index 200b95db73dd2a825c0f733680341570b26c5894..5c09c46b5e565b25629ed01901faa96e99a3d9d8 100644 (file)
@@ -446,6 +446,13 @@ class MinidomTest(unittest.TestCase):
         dom.unlink()
         self.confirm(domstr == str.replace("\n", "\r\n"))
 
+    def test_toPrettyXML_perserves_content_of_text_node(self):
+        str = '<A>B</A>'
+        dom = parseString(str)
+        dom2 = parseString(dom.toprettyxml())
+        self.assertEqual(dom.childNodes[0].childNodes[0].toxml(),
+                         dom2.childNodes[0].childNodes[0].toxml())
+
     def testProcessingInstruction(self):
         dom = parseString('<e><?mypi \t\n data \t\n ?></e>')
         pi = dom.documentElement.firstChild
index 218c62ed5fb475f85a70799109003badfa997abd..386494d288ee900ca4e020f39d20a95e7779575f 100644 (file)
@@ -836,7 +836,9 @@ class Element(Node):
             _write_data(writer, attrs[a_name].value)
             writer.write("\"")
         if self.childNodes:
-            writer.write(">%s"%(newl))
+            writer.write(">")
+            if self.childNodes[0].nodeType != Node.TEXT_NODE:
+                writer.write(newl)
             for node in self.childNodes:
                 node.writexml(writer,indent+addindent,addindent,newl)
             writer.write("%s</%s>%s" % (indent,self.tagName,newl))
@@ -1061,7 +1063,7 @@ class Text(CharacterData):
         return newText
 
     def writexml(self, writer, indent="", addindent="", newl=""):
-        _write_data(writer, "%s%s%s"%(indent, self.data, newl))
+        _write_data(writer, self.data)
 
     # DOM Level 3 (WD 9 April 2002)
 
index 408d91be8534332897eb35a6cbac0e7b3822a840..5bf395b9e7466a96ae250021903d9eb6cc1da2f2 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -468,6 +468,7 @@ Lou Kates
 Hiroaki Kawai
 Sebastien Keim
 Ryan Kelly
+Dan Kenigsberg
 Robert Kern
 Randall Kern
 Magnus Kessler
index f13fbe8d3e9ef1b08270b5643f106a1a328ad613..42627a269285fa0aff705b970a2146c2a1cd5ca2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #4147: minidom's toprettyxml no longer adds whitespace to text nodes.
+
 - Issue #13034: When decoding some SSL certificates, the subjectAltName
   extension could be unreported.