Final scour 0.18: more fixes to XML serialization (wellformedness), some unit tests, update to package script to use zip file and to package the inkscape extension

This commit is contained in:
JSCHILL1 2009-08-09 22:25:20 -05:00
parent 5f5c8a431d
commit eb2a7a05ac
6 changed files with 60 additions and 7 deletions

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
SCOURVER="0.18" SCOURVER="0.18"
cd .. cd ..
tar cvf scour/tarballs/scour-$SCOURVER.tar scour/scour.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html zip scour/tarballs/scour-$SCOURVER.zip scour/scour.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html
gzip scour/tarballs/scour-$SCOURVER.tar
cd scour cd scour
zip tarballs/scour-inkscape-extension-$SCOURVER.zip scour.inx scour.inkscape.py scour.py svg_regex.py

View file

@ -13,11 +13,11 @@
<header> <header>
<h2><a href="#0.18">Version 0.18</a></h2> <h2><a href="#0.18">Version 0.18</a></h2>
</header> </header>
<p>Aug 5th, 2009</p> <p>Aug 9th, 2009</p>
<ul> <ul>
<li>Remove attributes of gradients if they contain default values</li> <li>Remove attributes of gradients if they contain default values</li>
<li>Reduce bezier/quadratic (c/q) segments to their shorthand equivalents (s/t)</li> <li>Reduce bezier/quadratic (c/q) segments to their shorthand equivalents (s/t)</li>
<li>Custom XML serialization such that id/xml:id is printed first (Thanks to Richard Hutch for the suggestion)</li> <li>Move to a custom XML serialization such that id/xml:id is printed first (Thanks to Richard Hutch for the suggestion)</li>
<li>Added --indent option to specify indentation type (default='space', other options: 'none', 'tab')</li> <li>Added --indent option to specify indentation type (default='space', other options: 'none', 'tab')</li>
</ul> </ul>
</section> </section>

View file

@ -1876,6 +1876,23 @@ def remapNamespacePrefix(node, oldprefix, newprefix):
for child in node.childNodes : for child in node.childNodes :
remapNamespacePrefix(child, oldprefix, newprefix) remapNamespacePrefix(child, oldprefix, newprefix)
def makeWellFormed(str):
newstr = str
# encode & as &amp; ( must do this first so that &lt; does not become &amp;lt; )
if str.find('&') != -1:
newstr = str.replace('&', '&amp;')
# encode < as &lt;
if str.find("<") != -1:
newstr = str.replace('<', '&lt;')
# encode > as &gt; (TODO: is this necessary?)
if str.find('>') != -1:
newstr = str.replace('>', '&gt;')
return newstr
# hand-rolled serialization function that has the following benefits: # hand-rolled serialization function that has the following benefits:
# - pretty printing # - pretty printing
# - somewhat judicious use of whitespace # - somewhat judicious use of whitespace
@ -1912,7 +1929,9 @@ def serializeXML(element, options, ind = 0):
if attr.nodeValue.find('"') != -1: if attr.nodeValue.find('"') != -1:
quot = "'" quot = "'"
outString += ' ' + attr.nodeName + '=' + quot + attr.nodeValue + quot attrValue = makeWellFormed( attr.nodeValue )
outString += ' ' + attr.nodeName + '=' + quot + attrValue + quot
# if no children, self-close # if no children, self-close
children = element.childNodes children = element.childNodes
@ -1930,9 +1949,9 @@ def serializeXML(element, options, ind = 0):
# trim it only in the case of not being a child of an element # trim it only in the case of not being a child of an element
# where whitespace might be important # where whitespace might be important
if element.nodeName in ["text", "tspan", "textPath", "tref", "title", "desc", "textArea"]: if element.nodeName in ["text", "tspan", "textPath", "tref", "title", "desc", "textArea"]:
outString += child.nodeValue outString += makeWellFormed(child.nodeValue)
else: else:
outString += child.nodeValue.strip() outString += makeWellFormed(child.nodeValue.strip())
# CDATA node # CDATA node
elif child.nodeType == 4: elif child.nodeType == 4:
outString += '<![CDATA[' + child.nodeValue + ']]>' outString += '<![CDATA[' + child.nodeValue + ']]>'

View file

@ -87,6 +87,7 @@ class ScourOptions:
embed_rasters = False embed_rasters = False
keep_editor_data = False keep_editor_data = False
strip_xml_prolog = False strip_xml_prolog = False
indent_type = "space"
# 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)
def fetch(req, indoc,**params): def fetch(req, indoc,**params):

View file

@ -833,6 +833,30 @@ class CDATAInXml(unittest.TestCase):
</svg>''', </svg>''',
'Improperly serialized the cdata unit tests') 'Improperly serialized the cdata unit tests')
class WellFormedXMLLesserThanInAttrValue(unittest.TestCase):
def runTest(self):
wellformed = scour.scourString(open('unittests/xml-well-formed.svg').read())
self.assert_( wellformed.find('unicode="&lt;"') != -1,
"Improperly serialized &lt; in attribute value")
class WellFormedXMLAmpersandInAttrValue(unittest.TestCase):
def runTest(self):
wellformed = scour.scourString(open('unittests/xml-well-formed.svg').read())
self.assert_( wellformed.find('unicode="&amp;"') != -1,
'Improperly serialized &amp; in attribute value' )
class WellFormedXMLLesserThanInTextContent(unittest.TestCase):
def runTest(self):
wellformed = scour.scourString(open('unittests/xml-well-formed.svg').read())
self.assert_( wellformed.find('<title>2 &lt; 5</title>') != -1,
'Improperly serialized &lt; in text content')
class WellFormedXMLAmpersandInTextContent(unittest.TestCase):
def runTest(self):
wellformed = scour.scourString(open('unittests/xml-well-formed.svg').read())
self.assert_( wellformed.find('<desc>Peanut Butter &amp; Jelly</desc>') != -1,
'Improperly serialized &amp; in text content')
# 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 # TODO: write tests for --keep-editor-data

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg">
<!-- &lt;Jack &amp; Jill&gt; -->
<title>2 &lt; 5</title>
<desc>Peanut Butter &amp; Jelly</desc>
<glyph id="lt" unicode="&lt;"/>
<glyph id="amp" unicode="&amp;"/>
<text x="50" y="50">&#x389;TML &#x26; CSS</text>
</svg>

After

Width:  |  Height:  |  Size: 320 B