]> granicus.if.org Git - python/commitdiff
[Patch #1094164] replaceChild(x,x) ends up removing x of the tree. Add fix from...
authorAndrew M. Kuchling <amk@amk.ca>
Tue, 22 Nov 2005 19:03:16 +0000 (19:03 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Tue, 22 Nov 2005 19:03:16 +0000 (19:03 +0000)
Lib/test/test_minidom.py
Lib/xml/dom/minidom.py

index 8b4c71523c155ec53a698353d0fb1bd0259d64f7..68aac0f44a2fbe7b36b219b85fdc65cb472583d9 100644 (file)
@@ -1127,6 +1127,17 @@ def testWholeText():
     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>")
index 4bb4ef49ff1d0aa14b793d75da9eacef49c636c6..84be99b67a18b4d8c39661081fe8ece96b20ab09 100644 (file)
@@ -135,10 +135,10 @@ class Node(xml.dom.Node, GetattrMagic):
         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: