[Python-checkins] r63563 - in python/trunk: Lib/test/test_minidom.py Lib/xml/dom/minidom.py Misc/NEWS

martin.v.loewis python-checkins at python.org
Fri May 23 17:18:29 CEST 2008


Author: martin.v.loewis
Date: Fri May 23 17:18:28 2008
New Revision: 63563

Log:
Issue #1390: Raise ValueError in toxml when an invalid comment would
otherwise be produced.


Modified:
   python/trunk/Lib/test/test_minidom.py
   python/trunk/Lib/xml/dom/minidom.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Lib/test/test_minidom.py
==============================================================================
--- python/trunk/Lib/test/test_minidom.py	(original)
+++ python/trunk/Lib/test/test_minidom.py	Fri May 23 17:18:28 2008
@@ -1314,6 +1314,11 @@
             for i in range(len(n1.childNodes)):
                 stack.append((n1.childNodes[i], n2.childNodes[i]))
 
+    def testSerializeCommentNodeWithDoubleHyphen(self):
+        doc = create_doc_without_doctype()
+        doc.appendChild(doc.createComment("foo--bar"))
+        self.assertRaises(ValueError, doc.toxml)
+
 def test_main():
     run_unittest(MinidomTest)
 

Modified: python/trunk/Lib/xml/dom/minidom.py
==============================================================================
--- python/trunk/Lib/xml/dom/minidom.py	(original)
+++ python/trunk/Lib/xml/dom/minidom.py	Fri May 23 17:18:28 2008
@@ -1128,6 +1128,8 @@
         self.data = self.nodeValue = data
 
     def writexml(self, writer, indent="", addindent="", newl=""):
+        if "--" in self.data:
+            raise ValueError("'--' is not allowed in a comment node")
         writer.write("%s<!--%s-->%s" % (indent, self.data, newl))
 
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri May 23 17:18:28 2008
@@ -59,6 +59,9 @@
 Library
 -------
 
+- Issue #1390: Raise ValueError in toxml when an invalid comment would
+  otherwise be produced.
+
 - Issue #2914: TimedRotatingFileHandler now takes an optional keyword
   argument "utc" to use UTC time rather than local time.
 


More information about the Python-checkins mailing list