diff --git a/scour/scour.py b/scour/scour.py index 9d19906..d0b69c1 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -3390,7 +3390,9 @@ def properlySizeDoc(docElement, options): # else we have a statically sized image and we should try to remedy that # parse viewBox attribute - vbSep = RE_COMMA_WSP.split(docElement.getAttribute('viewBox')) + viewBox = docElement.getAttribute('viewBox') + lengths = RE_COMMA_WSP.split(viewBox) + vbSep = [length for length in lengths if length.strip()] # if we have a valid viewBox we need to check it if len(vbSep) == 4: try: @@ -3819,7 +3821,7 @@ def scourString(in_string, options=None, stats=None): viewBox = doc.documentElement.getAttribute('viewBox') if viewBox: lengths = RE_COMMA_WSP.split(viewBox) - lengths = [scourUnitlessLength(length) for length in lengths] + lengths = [scourUnitlessLength(length) for length in lengths if length.strip()] doc.documentElement.setAttribute('viewBox', ' '.join(lengths)) # more length scouring in this function diff --git a/test_scour.py b/test_scour.py index 549333f..dff1331 100755 --- a/test_scour.py +++ b/test_scour.py @@ -2786,6 +2786,13 @@ class ViewBox(unittest.TestCase): self.assertEqual(width, '', "width not removed with '--enable-viewboxing'.") self.assertEqual(height, '', "height not removed with '--enable-viewboxing'.") + def test_viewbox_remove_width_and_height_ws(self): + doc = scourXmlFile('unittests/viewbox-remove-ws.svg', parse_args(['--enable-viewboxing'])) + width = doc.documentElement.getAttribute('width') + height = doc.documentElement.getAttribute('height') + self.assertEqual(width, '', "width not removed with '--enable-viewboxing'.") + self.assertEqual(height, '', "height not removed with '--enable-viewboxing'.") + # TODO: write tests for --keep-editor-data diff --git a/unittests/viewbox-remove-ws.svg b/unittests/viewbox-remove-ws.svg new file mode 100644 index 0000000..3cd23c8 --- /dev/null +++ b/unittests/viewbox-remove-ws.svg @@ -0,0 +1,3 @@ + + +