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.
This commit is contained in:
parent
f8c88f0dfa
commit
60b48353b3
4 changed files with 28 additions and 4 deletions
11
scour.py
11
scour.py
|
|
@ -2125,10 +2125,13 @@ def parseListOfPoints(s):
|
||||||
# we got negative coords
|
# we got negative coords
|
||||||
else:
|
else:
|
||||||
for j in xrange(len(negcoords)):
|
for j in xrange(len(negcoords)):
|
||||||
# first number could be positive
|
|
||||||
if j == 0:
|
if j == 0:
|
||||||
|
# first number could be positive
|
||||||
if negcoords[0] != '':
|
if negcoords[0] != '':
|
||||||
nums.append(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
|
# otherwise all other strings will be negative
|
||||||
else:
|
else:
|
||||||
# unless we accidentally split a number that was in scientific notation
|
# 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
|
# must process the document object separately, because its
|
||||||
# documentElement's nodes have None as their parentNode
|
# documentElement's nodes have None as their parentNode
|
||||||
for subelement in element.childNodes:
|
for subelement in element.childNodes:
|
||||||
if isinstance(element, xml.dom.minidom.Comment):
|
if isinstance(subelement, xml.dom.minidom.Comment):
|
||||||
numCommentBytes += len(element.data)
|
numCommentBytes += len(subelement.data)
|
||||||
element.documentElement.removeChild(subelement)
|
element.removeChild(subelement)
|
||||||
else:
|
else:
|
||||||
removeComments(subelement)
|
removeComments(subelement)
|
||||||
elif isinstance(element, xml.dom.minidom.Comment):
|
elif isinstance(element, xml.dom.minidom.Comment):
|
||||||
|
|
|
||||||
13
testscour.py
13
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',
|
self.assertEquals(p.getAttribute('points'), '100 -100 100 -100 100 -100 -100 -100 -100 200',
|
||||||
'Negative polyline coordinates not properly parsed')
|
'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):
|
class DoNotRemoveGroupsWithIDsInDefs(unittest.TestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
f = scour.scourXmlFile('unittests/important-groups-in-defs.svg')
|
f = scour.scourXmlFile('unittests/important-groups-in-defs.svg')
|
||||||
|
|
|
||||||
4
unittests/polygon-coord-neg-first.svg
Normal file
4
unittests/polygon-coord-neg-first.svg
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<polygon points="-100,-100,100-100,100-100-100,-100-100,200" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 156 B |
4
unittests/polyline-coord-neg-first.svg
Normal file
4
unittests/polyline-coord-neg-first.svg
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<polyline points="-100,-100,100-100,100-100-100,-100-100,200" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 157 B |
Loading…
Add table
Add a link
Reference in a new issue