diff --git a/scour.py b/scour.py index 659b7a2..c68295c 100755 --- a/scour.py +++ b/scour.py @@ -420,12 +420,12 @@ def findReferencedElements(node, ids=None): # if this node is a style element, parse its text into CSS if node.nodeName == 'style' and node.namespaceURI == NS['SVG']: # node.firstChild will be either a CDATA or a Text node - cssRules = parseCssString(node.firstChild.nodeValue) - for rule in cssRules: - for propname in rule['properties']: - propval = rule['properties'][propname] - findReferencingProperty(node, propname, propval, ids) - + if node.firstChild != None: + cssRules = parseCssString(node.firstChild.nodeValue) + for rule in cssRules: + for propname in rule['properties']: + propval = rule['properties'][propname] + findReferencingProperty(node, propname, propval, ids) return ids # else if xlink:href is set, then grab the id diff --git a/testscour.py b/testscour.py index e0f49af..10c5547 100755 --- a/testscour.py +++ b/testscour.py @@ -957,6 +957,16 @@ class EnsurePreserveWhitespaceOnNonTextElements(unittest.TestCase): self.assertEquals( s.count('\n'), 5, 'Did not properly preserve whitespace on elements even if they were not textual') +class HandleEmptyStyleElement(unittest.TestCase): + def runTest(self): + try: + styles = scour.scourXmlFile('unittests/empty-style.svg').getElementsByTagNameNS(SVGNS, 'style') + fail = len(styles) != 1 + except AttributeError: + fail = True + self.assertEquals( fail, False, + 'Could not handle an empty style element') + # TODO; write a test for embedding rasters # TODO: write a test for --disable-embed-rasters # TODO: write tests for --keep-editor-data diff --git a/unittests/empty-style.svg b/unittests/empty-style.svg new file mode 100644 index 0000000..34bab4c --- /dev/null +++ b/unittests/empty-style.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file