scour: Fix another variant of the crash from #260

Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
Niels Thykier 2020-09-18 18:30:24 +00:00
parent 92e64f0d7f
commit 476ad1765d
No known key found for this signature in database
GPG key ID: A65B78DBE67C7AAC
4 changed files with 49 additions and 30 deletions

View file

@ -1200,11 +1200,11 @@ def mergeSiblingGroupsWithCommonAttributes(elem):
for node in nodes: for node in nodes:
if node.nodeType == Node.ELEMENT_NODE and node.nodeName == 'g' and node.namespaceURI == NS['SVG']: if node.nodeType == Node.ELEMENT_NODE and node.nodeName == 'g' and node.namespaceURI == NS['SVG']:
# Merge # Merge
primaryGroup.childNodes.extend(node.childNodes) for child in node.childNodes[:]:
node.childNodes = [] primaryGroup.appendChild(child)
elem.removeChild(node).unlink()
else: else:
primaryGroup.childNodes.append(node) primaryGroup.appendChild(node)
elem.childNodes.remove(node)
# each child gets the same treatment, recursively # each child gets the same treatment, recursively
for childNode in elem.childNodes: for childNode in elem.childNodes:

View file

@ -2099,6 +2099,12 @@ class GroupSiblingMerge(unittest.TestCase):
self.assertEqual(doc.getElementsByTagName('g').length, 8, self.assertEqual(doc.getElementsByTagName('g').length, 8,
'Sibling merging is disabled by --disable-group-collapsing') '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): class GroupCreation(unittest.TestCase):

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" viewBox="0 0 141.732 141.732" xml:space="preserve">
<g>
<g clip-path="url(#SVGID_2_)">
<path d="M1,1" fill="#fdebc8" stroke="#000" stroke-width=".5" stroke-miterlimit="10"/>
</g>
<g clip-path="url(#SVGID_2_)">
<g>
<path opacity=".5" clip-path="url(#SVGID_4_)" fill="#fff" d="M1,1"/>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 528 B

View file

@ -1,29 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"> <svg xmlns="http://www.w3.org/2000/svg">
<desc>Produced by GNUPLOT 5.2 patchlevel 8</desc> <desc>Produced by GNUPLOT 5.2 patchlevel 8</desc>
<rect width="900" height="600" fill="none"/> <rect width="900" height="600" fill="none"/>
<g color="black" fill="none"> <g color="black" fill="none">
<path d="m88.5 564h9m777.5 0h-9" stroke="#000"/> <path d="m88.5 564h9m777.5 0h-9" stroke="#000"/>
<g transform="translate(80.2,567.9)" fill="#000" font-family="Arial" font-size="12" text-anchor="end"> <g transform="translate(80.2,567.9)" fill="#000" font-family="Arial" font-size="12" text-anchor="end">
<text><tspan font-family="Arial">0</tspan></text> <text><tspan font-family="Arial">0</tspan></text>
</g> </g>
</g> </g>
<g color="black" fill="none"> <g color="black" fill="none">
<path d="m88.5 473h9m777.5 0h-9" stroke="#000"/> <path d="m88.5 473h9m777.5 0h-9" stroke="#000"/>
<g transform="translate(80.2,476.9)" fill="#000" font-family="Arial" font-size="12" text-anchor="end"> <g transform="translate(80.2,476.9)" fill="#000" font-family="Arial" font-size="12" text-anchor="end">
<text><tspan font-family="Arial">5000</tspan></text> <text><tspan font-family="Arial">5000</tspan></text>
</g> </g>
</g> </g>
<g color="black" fill="none"> <g color="black" fill="none">
<path d="m88.5 382h9m777.5 0h-9" stroke="#000"/> <path d="m88.5 382h9m777.5 0h-9" stroke="#000"/>
<g transform="translate(80.2,385.9)" fill="#000" font-family="Arial" font-size="12" text-anchor="end"> <g transform="translate(80.2,385.9)" fill="#000" font-family="Arial" font-size="12" text-anchor="end">
<text><tspan font-family="Arial">10000</tspan></text> <text><tspan font-family="Arial">10000</tspan></text>
</g> </g>
</g> </g>
<g color="black" fill="none"> <g color="black" fill="none">
<path d="m88.5 291h9m777.5 0h-9" stroke="#000"/> <path d="m88.5 291h9m777.5 0h-9" stroke="#000"/>
<g transform="translate(80.2,294.9)" fill="#000" font-family="Arial" font-size="12" text-anchor="end"> <g transform="translate(80.2,294.9)" fill="#000" font-family="Arial" font-size="12" text-anchor="end">
<text><tspan font-family="Arial">15000</tspan></text> <text><tspan font-family="Arial">15000</tspan></text>
</g> </g>
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before After
Before After