We don't want spaces in the serialized value of style attributes.

Add a unittest that should catch this and other issues with parsing/serializing the `style` attribute
This commit is contained in:
Eduard Braun 2016-09-11 14:01:04 +02:00
parent b065137187
commit 082b579410
3 changed files with 10 additions and 1 deletions

View file

@ -3105,7 +3105,7 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False):
attrValue = makeWellFormed( attr.nodeValue ) attrValue = makeWellFormed( attr.nodeValue )
if attr.nodeName == 'style': if attr.nodeName == 'style':
# sort declarations # sort declarations
attrValue = '; '.join([p for p in sorted(attrValue.split(';'))]) attrValue = ';'.join([p for p in sorted(attrValue.split(';'))])
outParts.append(' ') outParts.append(' ')
# preserve xmlns: if it is a namespace prefix declaration # preserve xmlns: if it is a namespace prefix declaration

View file

@ -1589,6 +1589,13 @@ class DocWithNoFlowtext(unittest.TestCase):
except Exception as e: except Exception as e:
self.fail("exception '{}' was raised, and we didn't expect that!".format(e)) self.fail("exception '{}' was raised, and we didn't expect that!".format(e))
class ParseStyleAttribute(unittest.TestCase):
def runTest(self):
doc = scour.scourXmlFile('unittests/style.svg')
self.assertEqual(doc.documentElement.getAttribute('style'), 'property1:value1;property2:value2;property3:value3',
'Style attribute not properly parsed and/or serialized')
# TODO: write tests for --enable-viewboxing # TODO: write tests for --enable-viewboxing
# TODO; write a test for embedding rasters # TODO; write a test for embedding rasters
# TODO: write a test for --disable-embed-rasters # TODO: write a test for --disable-embed-rasters

2
unittests/style.svg Normal file
View file

@ -0,0 +1,2 @@
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" style=" ; ;;property1: value1 ; ;; property2 :value2; property3 : value3 ;;; ;"></svg>

After

Width:  |  Height:  |  Size: 156 B