mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
[Patch #1094164] replaceChild(x,x) ends up removing x of the tree. Add fix from Felix Rabe and a test case
This commit is contained in:
parent
bb7e800506
commit
841d25ee66
2 changed files with 13 additions and 2 deletions
|
|
@ -1127,6 +1127,17 @@ def testWholeText():
|
||||||
checkWholeText(text, "cabd")
|
checkWholeText(text, "cabd")
|
||||||
checkWholeText(text2, "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 testReplaceWholeText():
|
||||||
def setup():
|
def setup():
|
||||||
doc = parseString("<doc>a<e/>d</doc>")
|
doc = parseString("<doc>a<e/>d</doc>")
|
||||||
|
|
|
||||||
|
|
@ -135,10 +135,10 @@ class Node(xml.dom.Node, GetattrMagic):
|
||||||
if newChild.nodeType not in self._child_node_types:
|
if newChild.nodeType not in self._child_node_types:
|
||||||
raise xml.dom.HierarchyRequestErr(
|
raise xml.dom.HierarchyRequestErr(
|
||||||
"%s cannot be child of %s" % (repr(newChild), repr(self)))
|
"%s cannot be child of %s" % (repr(newChild), repr(self)))
|
||||||
if newChild.parentNode is not None:
|
|
||||||
newChild.parentNode.removeChild(newChild)
|
|
||||||
if newChild is oldChild:
|
if newChild is oldChild:
|
||||||
return
|
return
|
||||||
|
if newChild.parentNode is not None:
|
||||||
|
newChild.parentNode.removeChild(newChild)
|
||||||
try:
|
try:
|
||||||
index = self.childNodes.index(oldChild)
|
index = self.childNodes.index(oldChild)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue