From 842123a39326223a91eb8e99ea8059e8158bc21c Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Mon, 29 Aug 2016 06:37:28 +0200 Subject: [PATCH] Fix improper comparison of numeric default attribute values with textvalues resulting in wrongly removed attributes (#101) For example for `orient="auto"` SVGLength() returns (value=0, units=Unit.INVALID); since the default value for `orient` is zero it was removed as there was check for a valid unit. --- scour/scour.py | 2 +- testscour.py | 12 ++++++++++-- unittests/orient-marker.svg | 12 ++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 unittests/orient-marker.svg diff --git a/scour/scour.py b/scour/scour.py index 2fc4921..53bb36e 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -1750,7 +1750,7 @@ def removeDefaultAttributeValue(node, attribute): return 1 else: nodeValue = SVGLength(node.getAttribute(attribute.name)) - if (attribute.value is None) or (nodeValue.value == attribute.value): + if (attribute.value is None) or ((nodeValue.value == attribute.value) and not (nodeValue.units == Unit.INVALID)): if (attribute.units is None) or (nodeValue.units == attribute.units) or (isinstance(attribute.units, list) and nodeValue.units in attribute.units): if (attribute.conditions is None) or attribute.conditions(node): node.removeAttribute(attribute.name) diff --git a/testscour.py b/testscour.py index fa30bb6..52f243c 100755 --- a/testscour.py +++ b/testscour.py @@ -1238,11 +1238,19 @@ class DoNotCommonizeAttributesOnReferencedElements(unittest.TestCase): class DoNotRemoveOverflowVisibleOnMarker(unittest.TestCase): def runTest(self): doc = scour.scourXmlFile('unittests/overflow-marker.svg') - self.assertEqual(doc.getElementsByTagName('marker')[0].getAttribute('overflow'), 'visible', + self.assertEqual(doc.getElementById('m1').getAttribute('overflow'), 'visible', 'Removed the overflow attribute when it was not using the default value') - self.assertEqual(doc.getElementsByTagName('marker')[1].getAttribute('overflow'), '', + self.assertEqual(doc.getElementById('m2').getAttribute('overflow'), '', 'Did not remove the overflow attribute when it was using the default value') +class DoNotRemoveOrientAutoOnMarker(unittest.TestCase): + def runTest(self): + doc = scour.scourXmlFile('unittests/orient-marker.svg') + self.assertEqual(doc.getElementById('m1').getAttribute('orient'), 'auto', + 'Removed the orient attribute when it was not using the default value') + self.assertEqual(doc.getElementById('m2').getAttribute('orient'), '', + 'Did not remove the orient attribute when it was using the default value') + class MarkerOnSvgElements(unittest.TestCase): def runTest(self): doc = scour.scourXmlFile('unittests/overflow-svg.svg') diff --git a/unittests/orient-marker.svg b/unittests/orient-marker.svg new file mode 100644 index 0000000..19ecd19 --- /dev/null +++ b/unittests/orient-marker.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + +