]> granicus.if.org Git - python/commitdiff
Issue #1390: Raise ValueError in toxml when an invalid comment would
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 23 May 2008 15:18:28 +0000 (15:18 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 23 May 2008 15:18:28 +0000 (15:18 +0000)
otherwise be produced.

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

index 97bca2c8a7cc548c93ba86857bd8dd36a129edaa..f1f137877e696f267492cf69cb69288be340bc92 100644 (file)
@@ -1314,6 +1314,11 @@ class MinidomTest(unittest.TestCase):
             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)
 
index ae960330c5bda69e2453df75835e20bd8db3fafe..02e82d90372a92668629ae1d2ed27ee1dae6ad90 100644 (file)
@@ -1128,6 +1128,8 @@ class Comment(Childless, CharacterData):
         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))
 
 
index 42d9f32937f60f32de36e559493fcdc4a43d9d73..c1f9555165f6576e5b58de0fbf3b8972d3bef1a2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -59,6 +59,9 @@ Extension Modules
 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.