diff --git a/scour/scour.py b/scour/scour.py index f462dc8..c987bb0 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -1200,11 +1200,11 @@ def mergeSiblingGroupsWithCommonAttributes(elem): for node in nodes: if node.nodeType == Node.ELEMENT_NODE and node.nodeName == 'g' and node.namespaceURI == NS['SVG']: # Merge - primaryGroup.childNodes.extend(node.childNodes) - node.childNodes = [] + for child in node.childNodes[:]: + primaryGroup.appendChild(child) + elem.removeChild(node).unlink() else: - primaryGroup.childNodes.append(node) - elem.childNodes.remove(node) + primaryGroup.appendChild(node) # each child gets the same treatment, recursively for childNode in elem.childNodes: diff --git a/test_scour.py b/test_scour.py index 5f44e03..549333f 100755 --- a/test_scour.py +++ b/test_scour.py @@ -2099,6 +2099,12 @@ class GroupSiblingMerge(unittest.TestCase): self.assertEqual(doc.getElementsByTagName('g').length, 8, 'Sibling merging is disabled by --disable-group-collapsing') + def test_sibling_merge_crash(self): + doc = scourXmlFile('unittests/group-sibling-merge-crash.svg', + parse_args([''])) + self.assertEqual(doc.getElementsByTagName('g').length, 1, + 'Sibling merge should work without causing crashes') + class GroupCreation(unittest.TestCase): diff --git a/unittests/group-sibling-merge-crash.svg b/unittests/group-sibling-merge-crash.svg new file mode 100644 index 0000000..3e50347 --- /dev/null +++ b/unittests/group-sibling-merge-crash.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/unittests/group-sibling-merge.svg b/unittests/group-sibling-merge.svg index 0a2181c..c7f0d02 100644 --- a/unittests/group-sibling-merge.svg +++ b/unittests/group-sibling-merge.svg @@ -1,29 +1,29 @@ -Produced by GNUPLOT 5.2 patchlevel 8 - - - - -0 - - - - - -5000 - - - - - -10000 - - - - - -15000 - - + Produced by GNUPLOT 5.2 patchlevel 8 + + + + + 0 + + + + + + 5000 + + + + + + 10000 + + + + + + 15000 + +