Fix Bug 405744: Keep namespace declarations when --keep-editor-data. Add tests.
This commit is contained in:
parent
4ee372f561
commit
8f50f0d509
3 changed files with 44 additions and 13 deletions
22
scour.py
22
scour.py
|
|
@ -1517,17 +1517,17 @@ def scourString(in_string, options=None):
|
||||||
pass
|
pass
|
||||||
while removeNamespacedAttributes( doc.documentElement, unwanted_ns ) > 0 :
|
while removeNamespacedAttributes( doc.documentElement, unwanted_ns ) > 0 :
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# remove the xmlns: declarations now
|
# remove the xmlns: declarations now
|
||||||
xmlnsDeclsToRemove = []
|
xmlnsDeclsToRemove = []
|
||||||
attrList = doc.documentElement.attributes
|
attrList = doc.documentElement.attributes
|
||||||
for num in range(attrList.length) :
|
for num in range(attrList.length) :
|
||||||
if attrList.item(num).nodeValue in unwanted_ns :
|
if attrList.item(num).nodeValue in unwanted_ns :
|
||||||
xmlnsDeclsToRemove.append(attrList.item(num).nodeName)
|
xmlnsDeclsToRemove.append(attrList.item(num).nodeName)
|
||||||
|
|
||||||
for attr in xmlnsDeclsToRemove :
|
for attr in xmlnsDeclsToRemove :
|
||||||
doc.documentElement.removeAttribute(attr)
|
doc.documentElement.removeAttribute(attr)
|
||||||
numAttrsRemoved += 1
|
numAttrsRemoved += 1
|
||||||
|
|
||||||
# repair style (remove unnecessary style properties and change them into XML attributes)
|
# repair style (remove unnecessary style properties and change them into XML attributes)
|
||||||
numStylePropsFixed = repairStyle(doc.documentElement, options)
|
numStylePropsFixed = repairStyle(doc.documentElement, options)
|
||||||
|
|
|
||||||
3
scra.py
3
scra.py
|
|
@ -83,6 +83,7 @@ class ScourOptions:
|
||||||
group_collapse = True
|
group_collapse = True
|
||||||
strip_ids = False
|
strip_ids = False
|
||||||
digits = 5
|
digits = 5
|
||||||
|
embed_rasters = False
|
||||||
keep_editor_data = False
|
keep_editor_data = False
|
||||||
|
|
||||||
# params are the form elements (if a checkbox is unchecked it will not be present)
|
# params are the form elements (if a checkbox is unchecked it will not be present)
|
||||||
|
|
@ -104,6 +105,6 @@ def fetch(req, indoc,**params):
|
||||||
|
|
||||||
fileitem = fs['upload']
|
fileitem = fs['upload']
|
||||||
if fileitem.filename:
|
if fileitem.filename:
|
||||||
req.write(scourString(fileitem.file.read()))
|
req.write(scourString(fileitem.file.read(), options))
|
||||||
else:
|
else:
|
||||||
req.write(scourString(indoc,options))
|
req.write(scourString(indoc,options))
|
||||||
|
|
|
||||||
32
testscour.py
32
testscour.py
|
|
@ -44,6 +44,7 @@ class ScourOptions:
|
||||||
strip_ids = False
|
strip_ids = False
|
||||||
digits = 5
|
digits = 5
|
||||||
embed_rasters = True
|
embed_rasters = True
|
||||||
|
keep_editor_data = False
|
||||||
|
|
||||||
class NoInkscapeElements(unittest.TestCase):
|
class NoInkscapeElements(unittest.TestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
|
|
@ -257,6 +258,34 @@ class NoInkscapeAttributes(unittest.TestCase):
|
||||||
findInkscapeAttr), False,
|
findInkscapeAttr), False,
|
||||||
'Found Inkscape attributes' )
|
'Found Inkscape attributes' )
|
||||||
|
|
||||||
|
class KeepInkscapeNamespaceDeclarationsWhenKeepEditorData(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
options = ScourOptions
|
||||||
|
options.keep_editor_data = True
|
||||||
|
attrs = scour.scourXmlFile('unittests/inkscape.svg', options).documentElement.attributes
|
||||||
|
FoundNamespace = False
|
||||||
|
for i in range(len(attrs)):
|
||||||
|
if attrs.item(i).nodeValue == 'http://www.inkscape.org/namespaces/inkscape':
|
||||||
|
FoundNamespace = True
|
||||||
|
break
|
||||||
|
self.assertEquals(True, FoundNamespace,
|
||||||
|
"Did not find Inkscape namespace declaration when using --keep-editor-data")
|
||||||
|
return False
|
||||||
|
|
||||||
|
class KeepSodipodiNamespaceDeclarationsWhenKeepEditorData(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
options = ScourOptions
|
||||||
|
options.keep_editor_data = True
|
||||||
|
attrs = scour.scourXmlFile('unittests/sodipodi.svg', options).documentElement.attributes
|
||||||
|
FoundNamespace = False
|
||||||
|
for i in range(len(attrs)):
|
||||||
|
if attrs.item(i).nodeValue == 'http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd':
|
||||||
|
FoundNamespace = True
|
||||||
|
break
|
||||||
|
self.assertEquals(True, FoundNamespace,
|
||||||
|
"Did not find Sodipodi namespace declaration when using --keep-editor-data")
|
||||||
|
return False
|
||||||
|
|
||||||
class KeepReferencedFonts(unittest.TestCase):
|
class KeepReferencedFonts(unittest.TestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
doc = scour.scourXmlFile('unittests/referenced-font.svg')
|
doc = scour.scourXmlFile('unittests/referenced-font.svg')
|
||||||
|
|
@ -604,13 +633,14 @@ class DoNotRemoveGroupsWithIDsInDefs(unittest.TestCase):
|
||||||
|
|
||||||
class AlwaysKeepClosePathSegments(unittest.TestCase):
|
class AlwaysKeepClosePathSegments(unittest.TestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
p= scour.scourXmlFile('unittests/path-with-closepath.svg').getElementsByTagNameNS(SVGNS, 'path')[0]
|
p = scour.scourXmlFile('unittests/path-with-closepath.svg').getElementsByTagNameNS(SVGNS, 'path')[0]
|
||||||
self.assertEquals(p.getAttribute('d'), 'M10,10h100v100h-100z',
|
self.assertEquals(p.getAttribute('d'), 'M10,10h100v100h-100z',
|
||||||
'Path with closepath not preserved')
|
'Path with closepath not preserved')
|
||||||
|
|
||||||
# TODO: write tests for --set-precision for path data, for polygon data, for attributes
|
# TODO: write tests for --set-precision for path data, for polygon data, for attributes
|
||||||
# TODO; write a test for embedding rasters
|
# TODO; write a test for embedding rasters
|
||||||
# TODO: write a test for --disable-embed-rasters
|
# TODO: write a test for --disable-embed-rasters
|
||||||
|
# TODO: write tests for --keep-editor-data
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue