This commit is contained in:
Alexey Ivanov 2022-04-01 16:48:46 -07:00 committed by GitHub
commit 30e5ad5629
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View file

@ -3390,7 +3390,9 @@ def properlySizeDoc(docElement, options):
# else we have a statically sized image and we should try to remedy that # else we have a statically sized image and we should try to remedy that
# parse viewBox attribute # 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 we have a valid viewBox we need to check it
if len(vbSep) == 4: if len(vbSep) == 4:
try: try:
@ -3819,7 +3821,7 @@ def scourString(in_string, options=None, stats=None):
viewBox = doc.documentElement.getAttribute('viewBox') viewBox = doc.documentElement.getAttribute('viewBox')
if viewBox: if viewBox:
lengths = RE_COMMA_WSP.split(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)) doc.documentElement.setAttribute('viewBox', ' '.join(lengths))
# more length scouring in this function # more length scouring in this function

View file

@ -2786,6 +2786,13 @@ class ViewBox(unittest.TestCase):
self.assertEqual(width, '', "width not removed with '--enable-viewboxing'.") self.assertEqual(width, '', "width not removed with '--enable-viewboxing'.")
self.assertEqual(height, '', "height 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 # TODO: write tests for --keep-editor-data

View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="123.456" height="654.321" viewBox=" 0 0 123.456 654.321 ">
</svg>

After

Width:  |  Height:  |  Size: 152 B