From 60b48353b36d76b2da6e46ae9419a78fb721e02e Mon Sep 17 00:00:00 2001 From: Hungerburg <> Date: Thu, 25 Aug 2011 22:26:05 -0400 Subject: [PATCH] Apply a modified patch by Hungerburg to fix bugs 833666, "scour does not clean comments if file starts with a comment", and bug 804238, whereby Scour fails to correctly parse a polygon/polyline if its first coordinate is negative. Unit tests added for the negative coordinate parsing. --- scour.py | 11 +++++++---- testscour.py | 13 +++++++++++++ unittests/polygon-coord-neg-first.svg | 4 ++++ unittests/polyline-coord-neg-first.svg | 4 ++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 unittests/polygon-coord-neg-first.svg create mode 100644 unittests/polyline-coord-neg-first.svg 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 @@ + + + +