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.
This commit is contained in:
parent
3511c05298
commit
842123a393
3 changed files with 23 additions and 3 deletions
|
|
@ -1750,7 +1750,7 @@ def removeDefaultAttributeValue(node, attribute):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
nodeValue = SVGLength(node.getAttribute(attribute.name))
|
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.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):
|
if (attribute.conditions is None) or attribute.conditions(node):
|
||||||
node.removeAttribute(attribute.name)
|
node.removeAttribute(attribute.name)
|
||||||
|
|
|
||||||
12
testscour.py
12
testscour.py
|
|
@ -1238,11 +1238,19 @@ class DoNotCommonizeAttributesOnReferencedElements(unittest.TestCase):
|
||||||
class DoNotRemoveOverflowVisibleOnMarker(unittest.TestCase):
|
class DoNotRemoveOverflowVisibleOnMarker(unittest.TestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
doc = scour.scourXmlFile('unittests/overflow-marker.svg')
|
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')
|
'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')
|
'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):
|
class MarkerOnSvgElements(unittest.TestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
doc = scour.scourXmlFile('unittests/overflow-svg.svg')
|
doc = scour.scourXmlFile('unittests/overflow-svg.svg')
|
||||||
|
|
|
||||||
12
unittests/orient-marker.svg
Normal file
12
unittests/orient-marker.svg
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<defs>
|
||||||
|
<marker id="m1" orient="auto">
|
||||||
|
<rect width="200" height="100"/>
|
||||||
|
</marker>
|
||||||
|
<marker id="m2" orient="0">
|
||||||
|
<rect width="200" height="100"/>
|
||||||
|
</marker>
|
||||||
|
</defs>
|
||||||
|
<line x2="100" y2="100" style="marker-start:url(#m1);marker-end:url(#m2)" stroke="#000" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 414 B |
Loading…
Add table
Add a link
Reference in a new issue