Index: Lib/test/test_minidom.py =================================================================== --- Lib/test/test_minidom.py (revision 60745) +++ Lib/test/test_minidom.py (working copy) @@ -1306,6 +1306,11 @@ and n2.ownerDocument.isSameNode(doc2)) 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: Lib/xml/dom/minidom.py =================================================================== --- Lib/xml/dom/minidom.py (revision 60745) +++ Lib/xml/dom/minidom.py (working copy) @@ -1126,6 +1126,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" % (indent, self.data, newl))