From 09a656287de73b61db2c5e5895d13e4482e48722 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sat, 18 Aug 2018 16:18:58 +0000 Subject: [PATCH] Avoid picking an id-less gradient to replace one with an id Closes: #203 Signed-off-by: Niels Thykier --- scour/scour.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scour/scour.py b/scour/scour.py index a46af61..61048e8 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -1395,6 +1395,19 @@ def removeDuplicateGradients(doc): continue master = bucket[0] duplicates = bucket[1:] + master_id = master.getAttribute('id') + if not master_id: + # If our selected "master" copy does not have an ID, + # then replace it with one that does (assuming any of + # them has one). This avoids broken images like we + # saw in GH#203 + for i in range(len(duplicates)): + dup = duplicates[i] + dup_id = dup.getAttribute('id') + if dup_id: + duplicates[i] = master + master = dup + break gradientsToRemove[master] = duplicates