[Python-checkins] commit of r41507 - in python/trunk/Lib: test xml/dom

andrew.kuchling@python.org andrew.kuchling at python.org
Tue Nov 22 20:03:21 CET 2005


Author: andrew.kuchling
Date: Tue Nov 22 20:03:16 2005
New Revision: 41507
Modified:
 python/trunk/Lib/test/test_minidom.py
 python/trunk/Lib/xml/dom/minidom.py
Log:
[Patch #1094164] replaceChild(x,x) ends up removing x of the tree. Add fix from Felix Rabe and a test case
Modified: python/trunk/Lib/test/test_minidom.py
==============================================================================
--- python/trunk/Lib/test/test_minidom.py	(original)
+++ python/trunk/Lib/test/test_minidom.py	Tue Nov 22 20:03:16 2005
@@ -1127,6 +1127,17 @@
 checkWholeText(text, "cabd")
 checkWholeText(text2, "cabd")
 
+def testPatch1094164 ():
+ doc = parseString("<doc><e/></doc>")
+ elem = doc.documentElement
+ e = elem.firstChild
+ confirm(e.parentNode is elem, "Before replaceChild()")
+ # Check that replacing a child with itself leaves the tree unchanged
+ elem.replaceChild(e, e)
+ confirm(e.parentNode is elem, "After replaceChild()")
+ 
+ 
+ 
 def testReplaceWholeText():
 def setup():
 doc = parseString("<doc>a<e/>d</doc>")
Modified: python/trunk/Lib/xml/dom/minidom.py
==============================================================================
--- python/trunk/Lib/xml/dom/minidom.py	(original)
+++ python/trunk/Lib/xml/dom/minidom.py	Tue Nov 22 20:03:16 2005
@@ -135,10 +135,10 @@
 if newChild.nodeType not in self._child_node_types:
 raise xml.dom.HierarchyRequestErr(
 "%s cannot be child of %s" % (repr(newChild), repr(self)))
- if newChild.parentNode is not None:
- newChild.parentNode.removeChild(newChild)
 if newChild is oldChild:
 return
+ if newChild.parentNode is not None:
+ newChild.parentNode.removeChild(newChild)
 try:
 index = self.childNodes.index(oldChild)
 except ValueError:


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /