From 27e4a179f277b568f04d482765ab773068ae6ab6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 23 May 2008 15:18:28 +0000 Subject: [PATCH] Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. --- Lib/test/test_minidom.py | 5 +++++ Lib/xml/dom/minidom.py | 2 ++ Misc/NEWS | 3 +++ 3 files changed, 10 insertions(+) diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 97bca2c8a7..f1f137877e 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -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) diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index ae960330c5..02e82d9037 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -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" % (indent, self.data, newl)) diff --git a/Misc/NEWS b/Misc/NEWS index 42d9f32937..c1f9555165 100644 --- 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. -- 2.50.1