Fix bug 833666, "scour does not clean comments if file starts with a comment", by correctly and efficiently iterating over the elements of a live sequence. Unit tests are updated.
This commit is contained in:
parent
4b10b6d627
commit
58ddeb855b
2 changed files with 12 additions and 2 deletions
8
scour.py
8
scour.py
|
|
@ -2575,7 +2575,9 @@ def removeComments(element) :
|
|||
if isinstance(element, xml.dom.minidom.Document):
|
||||
# must process the document object separately, because its
|
||||
# documentElement's nodes have None as their parentNode
|
||||
for subelement in element.childNodes:
|
||||
# iterate in reverse order to prevent mess-ups with renumbering
|
||||
for index in xrange(len(element.childNodes) - 1, -1, -1):
|
||||
subelement = element.childNodes[index]
|
||||
if isinstance(subelement, xml.dom.minidom.Comment):
|
||||
numCommentBytes += len(subelement.data)
|
||||
element.removeChild(subelement)
|
||||
|
|
@ -2585,7 +2587,9 @@ def removeComments(element) :
|
|||
numCommentBytes += len(element.data)
|
||||
element.parentNode.removeChild(element)
|
||||
else:
|
||||
for subelement in element.childNodes:
|
||||
# iterate in reverse order to prevent mess-ups with renumbering
|
||||
for index in xrange(len(element.childNodes) - 1, -1, -1):
|
||||
subelement = element.childNodes[index]
|
||||
removeComments(subelement)
|
||||
|
||||
def embedRasters(element, options) :
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<!-- Oh look a comment -->
|
||||
<!-- generated by foobar version 20120503 -->
|
||||
<!-- And another -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<!-- This comment is meant to test whether removing a comment before <svg>
|
||||
messes up removing comments thereafter -->
|
||||
<!-- And this one is meant to test whether iteration works correctly in
|
||||
<svg> as well as the document element -->
|
||||
</svg>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 131 B After Width: | Height: | Size: 448 B |
Loading…
Add table
Add a link
Reference in a new issue