From 082b579410a852dd1001115609773519e8d20dce Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 11 Sep 2016 14:01:04 +0200 Subject: [PATCH] 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 --- scour/scour.py | 2 +- testscour.py | 7 +++++++ unittests/style.svg | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 unittests/style.svg diff --git a/scour/scour.py b/scour/scour.py index 51cc248..da212fb 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -3105,7 +3105,7 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False): attrValue = makeWellFormed( attr.nodeValue ) if attr.nodeName == 'style': # sort declarations - attrValue = '; '.join([p for p in sorted(attrValue.split(';'))]) + attrValue = ';'.join([p for p in sorted(attrValue.split(';'))]) outParts.append(' ') # preserve xmlns: if it is a namespace prefix declaration diff --git a/testscour.py b/testscour.py index e97f252..28b3148 100755 --- a/testscour.py +++ b/testscour.py @@ -1589,6 +1589,13 @@ class DocWithNoFlowtext(unittest.TestCase): except Exception as 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 a test for embedding rasters # TODO: write a test for --disable-embed-rasters diff --git a/unittests/style.svg b/unittests/style.svg new file mode 100644 index 0000000..dfe5b8d --- /dev/null +++ b/unittests/style.svg @@ -0,0 +1,2 @@ + +