Malte Helmert added the comment:

I can reproduce the bug on trunk (r60511). At first I thought the
behaviour might be caused by the testcase removing items from the
children list while iterating over it, but this is not the case; the
exception is raised upon the first removal already.

Here is a shorter testcase:
========================================
from xml.dom import minidom

def testme(xmltext):
    node = minidom.parseString(xmltext).documentElement
    for child in node.childNodes:
        if child.nodeValue == "t":
            child.nodeValue = ""
    node.normalize()

    child = node.firstChild
    while child:
        next = child.nextSibling
        if child.nodeType == child.TEXT_NODE and child.nodeValue == "":
            node.removeChild(child)
        child = next
    return node

print testme("<o><i/>tt</o>").toxml()
print testme("<o><i/>t</o>").toxml()
========================================

The second call to testme fails with an xml.dom.NotFoundErr, but it
should succeed and print "<o><i/></o>".


While this appears to be a genuine bug, I don't agree with the proposed
fix. I'm not sure if calling removeChild (which mutates self.childNodes)
from within normalize (which iterates over self.childNodes at that time)
is safe, and even if it is, it would make normalize O(N^2) (not taking
into account recursion) where it should be O(N).

----------
nosy: +maltehelmert

_____________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1433694>
_____________________________________
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to