call sanitizeOptions() in start() to prevent a third-party breakage
This commit is contained in:
parent
c45f050fe6
commit
6cf8c2b7d9
2 changed files with 40 additions and 8 deletions
|
|
@ -3523,10 +3523,10 @@ def scourString(in_string, options=None):
|
|||
# input is a filename
|
||||
# returns the minidom doc representation of the SVG
|
||||
def scourXmlFile(filename, options=None):
|
||||
# we need to set infilename (otherwise relative references in the SVG won't work)
|
||||
if options is None:
|
||||
options = generateDefaultOptions()
|
||||
options.infilename = filename
|
||||
# sanitize options (take missing attributes from defaults, discard unknown attributes)
|
||||
options = sanitizeOptions(options)
|
||||
# we need to make sure infilename is set correctly (otherwise relative references in the SVG won't work)
|
||||
options.ensure_value("infilename", filename)
|
||||
|
||||
# open the file and scour it
|
||||
with open(filename, "rb") as f:
|
||||
|
|
@ -3783,6 +3783,8 @@ def getReport():
|
|||
|
||||
|
||||
def start(options, input, output):
|
||||
# sanitize options (take missing attributes from defaults, discard unknown attributes)
|
||||
options = sanitizeOptions(options)
|
||||
|
||||
start = walltime()
|
||||
|
||||
|
|
|
|||
38
testscour.py
38
testscour.py
|
|
@ -30,7 +30,7 @@ import unittest
|
|||
import six
|
||||
from six.moves import map, range
|
||||
|
||||
from scour.scour import makeWellFormed, parse_args, scourString, scourXmlFile, run
|
||||
from scour.scour import makeWellFormed, parse_args, scourString, scourXmlFile, start, run
|
||||
from scour.svg_regex import svg_parser
|
||||
from scour import __version__
|
||||
|
||||
|
|
@ -58,15 +58,45 @@ class ScourOptions:
|
|||
|
||||
class EmptyOptions(unittest.TestCase):
|
||||
|
||||
def runTest(self):
|
||||
MINIMAL_SVG = '<?xml version="1.0" encoding="UTF-8"?>\n' \
|
||||
'<svg xmlns="http://www.w3.org/2000/svg"/>\n'
|
||||
|
||||
def test_scourString(self):
|
||||
options = ScourOptions
|
||||
try:
|
||||
scourXmlFile('unittests/ids-to-strip.svg', options)
|
||||
scourString(self.MINIMAL_SVG, options)
|
||||
fail = False
|
||||
except:
|
||||
fail = True
|
||||
self.assertEqual(fail, False,
|
||||
'Exception when calling Scour with empty options object')
|
||||
'Exception when calling "scourString" with empty options object')
|
||||
|
||||
def test_scourXmlFile(self):
|
||||
options = ScourOptions
|
||||
try:
|
||||
scourXmlFile('unittests/minimal.svg', options)
|
||||
fail = False
|
||||
except:
|
||||
fail = True
|
||||
self.assertEqual(fail, False,
|
||||
'Exception when calling "scourXmlFile" with empty options object')
|
||||
|
||||
def test_start(self):
|
||||
options = ScourOptions
|
||||
input = open('unittests/minimal.svg', 'rb')
|
||||
output = open('testscour_temp.svg', 'wb')
|
||||
|
||||
stdout_temp = sys.stdout
|
||||
sys.stdout = None
|
||||
try:
|
||||
start(options, input, output)
|
||||
fail = False
|
||||
except:
|
||||
fail = True
|
||||
sys.stdout = stdout_temp
|
||||
|
||||
self.assertEqual(fail, False,
|
||||
'Exception when calling "start" with empty options object')
|
||||
|
||||
|
||||
class InvalidOptions(unittest.TestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue