Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions scour/scour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -3819,7 +3821,7 @@ def xmlnsUnused(prefix, namespace):
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
Expand Down
7 changes: 7 additions & 0 deletions test_scour.py
Original file line number Diff line number Diff line change
Expand Up @@ -2786,6 +2786,13 @@ def test_viewbox_remove_width_and_height(self):
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

Expand Down
3 changes: 3 additions & 0 deletions unittests/viewbox-remove-ws.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.