Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 688b9e3

Browse files
committed
#777884: make .normalize() do nothing for childless nodes, instead of raising an exception
1 parent ea64a6a commit 688b9e3

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/test/test_minidom.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,14 @@ def testNormalizeRecursion(self):
951951
doc.unlink()
952952

953953

954+
def testBug0777884(self):
955+
doc = parseString("<o>text</o>")
956+
text = doc.documentElement.childNodes[0]
957+
self.assertEquals(text.nodeType, Node.TEXT_NODE)
958+
# Should run quietly, doing nothing.
959+
text.normalize()
960+
doc.unlink()
961+
954962
def testBug1433694(self):
955963
doc = parseString("<o><i/>t</o>")
956964
node = doc.documentElement

Lib/xml/dom/minidom.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,10 @@ def removeChild(self, oldChild):
920920
raise xml.dom.NotFoundErr(
921921
self.nodeName + " nodes do not have children")
922922

923+
def normalize(self):
924+
# For childless nodes, normalize() has nothing to do.
925+
pass
926+
923927
def replaceChild(self, newChild, oldChild):
924928
raise xml.dom.HierarchyRequestErr(
925929
self.nodeName + " nodes do not have children")

0 commit comments

Comments
 (0)