From: Andrew M. Kuchling Date: Wed, 21 Feb 2001 01:30:26 +0000 (+0000) Subject: Patch #103854: raises an exception if a non-Attr node is passed to X-Git-Tag: v2.1b1~251 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bc8f72ccccb1acd697d5cdb3ff0711bfa98af00d;p=thirdparty%2FPython%2Fcpython.git Patch #103854: raises an exception if a non-Attr node is passed to NamedNodeMap.setNamedItem(). Martin, should I sync the PyXML tree, too, or do you want to do it? (I don't know if you're wrapping the 0.6.4 release right now.) --- diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 457480349a48..5cc1e692938b 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -98,6 +98,17 @@ def testLegalChildren(): else: print "dom.appendChild didn't raise HierarchyRequestErr" + nodemap = elem.attributes + try: nodemap.setNamedItem(text) + except HierarchyRequestErr: pass + else: + print "NamedNodeMap.setNamedItem didn't raise HierarchyRequestErr" + + try: nodemap.setNamedItemNS(text) + except HierarchyRequestErr: pass + else: + print "NamedNodeMap.setNamedItemNS didn't raise HierarchyRequestErr" + elem.appendChild(text) dom.unlink() diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index ef1a2bff2299..b4ae267511fd 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -378,6 +378,9 @@ class NamedNodeMap: self.setNamedItem(node) def setNamedItem(self, node): + if not isinstance(node, Attr): + raise HierarchyRequestErr, \ + "%s cannot be child of %s" % (repr(node), repr(self)) old = self._attrs.get(node.name) if old: old.unlink()