Skip to content

Commit 14f52dc

Browse files
author
martin.v.loewis
committed
Issue #1390: Raise ValueError in toxml when an invalid comment would
otherwise be produced. git-svn-id: http://svn.python.org/projects/python/trunk@63563 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 3c956f5 commit 14f52dc

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_minidom.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,11 @@ def testPickledDocument(self):
13141314
for i in range(len(n1.childNodes)):
13151315
stack.append((n1.childNodes[i], n2.childNodes[i]))
13161316

1317+
def testSerializeCommentNodeWithDoubleHyphen(self):
1318+
doc = create_doc_without_doctype()
1319+
doc.appendChild(doc.createComment("foo--bar"))
1320+
self.assertRaises(ValueError, doc.toxml)
1321+
13171322
def test_main():
13181323
run_unittest(MinidomTest)
13191324

Lib/xml/dom/minidom.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,8 @@ def __init__(self, data):
11281128
self.data = self.nodeValue = data
11291129

11301130
def writexml(self, writer, indent="", addindent="", newl=""):
1131+
if "--" in self.data:
1132+
raise ValueError("'--' is not allowed in a comment node")
11311133
writer.write("%s<!--%s-->%s" % (indent, self.data, newl))
11321134

11331135

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Extension Modules
5959
Library
6060
-------
6161

62+
- Issue #1390: Raise ValueError in toxml when an invalid comment would
63+
otherwise be produced.
64+
6265
- Issue #2914: TimedRotatingFileHandler now takes an optional keyword
6366
argument "utc" to use UTC time rather than local time.
6467

0 commit comments

Comments
 (0)