diff --git a/scour.py b/scour.py index 9737042..a3a8a74 100755 --- a/scour.py +++ b/scour.py @@ -2125,10 +2125,13 @@ def parseListOfPoints(s): # we got negative coords else: for j in xrange(len(negcoords)): - # first number could be positive if j == 0: + # first number could be positive if negcoords[0] != '': nums.append(negcoords[0]) + # but it could also be negative + elif len(nums) == 0: + nums.append('-' + negcoords[j]) # otherwise all other strings will be negative else: # unless we accidentally split a number that was in scientific notation @@ -2554,9 +2557,9 @@ def removeComments(element) : # must process the document object separately, because its # documentElement's nodes have None as their parentNode for subelement in element.childNodes: - if isinstance(element, xml.dom.minidom.Comment): - numCommentBytes += len(element.data) - element.documentElement.removeChild(subelement) + if isinstance(subelement, xml.dom.minidom.Comment): + numCommentBytes += len(subelement.data) + element.removeChild(subelement) else: removeComments(subelement) elif isinstance(element, xml.dom.minidom.Comment): diff --git a/testscour.py b/testscour.py index aabcb9c..bce1d13 100755 --- a/testscour.py +++ b/testscour.py @@ -704,6 +704,19 @@ class ScourPolylineNegativeCoords(unittest.TestCase): self.assertEquals(p.getAttribute('points'), '100 -100 100 -100 100 -100 -100 -100 -100 200', 'Negative polyline coordinates not properly parsed') +class ScourPolygonNegativeCoordFirst(unittest.TestCase): + def runTest(self): + p = scour.scourXmlFile('unittests/polygon-coord-neg-first.svg').getElementsByTagNameNS(SVGNS, 'polygon')[0] + # points="-100,-100,100-100,100-100-100,-100-100,200" /> + self.assertEquals(p.getAttribute('points'), '-100 -100 100 -100 100 -100 -100 -100 -100 200', + 'Negative polygon coordinates not properly parsed') + +class ScourPolylineNegativeCoordFirst(unittest.TestCase): + def runTest(self): + p = scour.scourXmlFile('unittests/polyline-coord-neg-first.svg').getElementsByTagNameNS(SVGNS, 'polyline')[0] + self.assertEquals(p.getAttribute('points'), '-100 -100 100 -100 100 -100 -100 -100 -100 200', + 'Negative polyline coordinates not properly parsed') + class DoNotRemoveGroupsWithIDsInDefs(unittest.TestCase): def runTest(self): f = scour.scourXmlFile('unittests/important-groups-in-defs.svg') diff --git a/unittests/polygon-coord-neg-first.svg b/unittests/polygon-coord-neg-first.svg new file mode 100644 index 0000000..9f87a3e --- /dev/null +++ b/unittests/polygon-coord-neg-first.svg @@ -0,0 +1,4 @@ + + + + diff --git a/unittests/polyline-coord-neg-first.svg b/unittests/polyline-coord-neg-first.svg new file mode 100644 index 0000000..41d1981 --- /dev/null +++ b/unittests/polyline-coord-neg-first.svg @@ -0,0 +1,4 @@ + + + +