Fix Bug 517064: Make XML well-formed again by properly translating the 5 XML entities

This commit is contained in:
JSCHILL1 2010-02-04 09:30:22 -06:00
parent 6230682a01
commit 6147bb2085
4 changed files with 28 additions and 19 deletions

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
SCOURVER="0.23" SCOURVER="0.24"
cd .. cd ..
zip scour/tarballs/scour-$SCOURVER.zip scour/scour.py scour/yocto_css.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/yocto_css.py scour/svg_regex.py scour/LICENSE scour/NOTICE scour/README.txt scour/release-notes.html
cd scour cd scour

View file

@ -9,11 +9,21 @@
<p>Copyright 2009, Jeff Schiller</p> <p>Copyright 2009, Jeff Schiller</p>
<section id="0.24">
<header>
<h2><a href="#0.24">Version 0.24</a></h2>
</header>
<p>2010-02-04</p>
<ul>
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/517064">Bug 517064</a> to make XML well-formed again</li>
</ul>
</section>
<section id="0.23"> <section id="0.23">
<header> <header>
<h2><a href="#0.23">Version 0.23</a></h2> <h2><a href="#0.23">Version 0.23</a></h2>
</header> </header>
<p>2009-01-04</p> <p>2010-01-04</p>
<ul> <ul>
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/482215">Bug 482215</a> by using os.linesep to end lines</li> <li>Fix <a href="https://bugs.launchpad.net/scour/+bug/482215">Bug 482215</a> by using os.linesep to end lines</li>
<li>Fix unittests to run properly in Windows</li> <li>Fix unittests to run properly in Windows</li>

View file

@ -72,7 +72,7 @@ except ImportError:
pass pass
APP = 'scour' APP = 'scour'
VER = '0.23' VER = '0.24'
COPYRIGHT = 'Copyright Jeff Schiller, 2010' COPYRIGHT = 'Copyright Jeff Schiller, 2010'
NS = { 'SVG': 'http://www.w3.org/2000/svg', NS = { 'SVG': 'http://www.w3.org/2000/svg',
@ -2021,20 +2021,14 @@ def remapNamespacePrefix(node, oldprefix, newprefix):
remapNamespacePrefix(child, oldprefix, newprefix) remapNamespacePrefix(child, oldprefix, newprefix)
def makeWellFormed(str): def makeWellFormed(str):
newstr = str newstr = ''
xml_ents = { '<':'&lt;', '>':'&gt;', '&':'&amp;', "'":'&apos;', '"':'&quot;'}
# encode & as &amp; ( must do this first so that &lt; does not become &amp;lt; ) for c in str:
if str.find('&') != -1: if c in xml_ents:
newstr = str.replace('&', '&amp;') newstr += xml_ents[c]
else:
newstr += c
# 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 return newstr
# hand-rolled serialization function that has the following benefits: # hand-rolled serialization function that has the following benefits:
@ -2278,7 +2272,7 @@ def scourString(in_string, options=None):
embedRasters(elem, options) embedRasters(elem, options)
# properly size the SVG document (ideally width/height should be 100% with a viewBox) # properly size the SVG document (ideally width/height should be 100% with a viewBox)
if options.viewboxing: if options.enable_viewboxing:
properlySizeDoc(doc.documentElement) properlySizeDoc(doc.documentElement)
# output the document as a pretty string with a single space for indent # output the document as a pretty string with a single space for indent
@ -2354,7 +2348,7 @@ _options_parser.add_option("--strip-xml-prolog",
action="store_true", dest="strip_xml_prolog", default=False, action="store_true", dest="strip_xml_prolog", default=False,
help="won't output the <?xml ?> prolog") help="won't output the <?xml ?> prolog")
_options_parser.add_option("--enable-viewboxing", _options_parser.add_option("--enable-viewboxing",
action="store_true", dest="viewboxing", default=False, action="store_true", dest="enable_viewboxing", default=False,
help="changes document width/height to 100%/100% and creates viewbox coordinates") help="changes document width/height to 100%/100% and creates viewbox coordinates")
# GZ: this is confusing, most people will be thinking in terms of # GZ: this is confusing, most people will be thinking in terms of

View file

@ -47,7 +47,7 @@ class ScourOptions:
keep_editor_data = False keep_editor_data = False
strip_xml_prolog = False strip_xml_prolog = False
indent_type = "space" indent_type = "space"
viewboxing = False enable_viewboxing = False
class NoInkscapeElements(unittest.TestCase): class NoInkscapeElements(unittest.TestCase):
def runTest(self): def runTest(self):
@ -983,6 +983,11 @@ class EnsureLineEndings(unittest.TestCase):
self.assertEquals( len(s.splitlines()), 4, self.assertEquals( len(s.splitlines()), 4,
'Did not output line ending character correctly') 'Did not output line ending character correctly')
class XmlEntities(unittest.TestCase):
def runTest(self):
self.assertEquals( scour.makeWellFormed('<>&"\''), '&lt;&gt;&amp;&quot;&apos;',
'Incorrectly translated XML entities')
# TODO: write tests for --enable-viewboxing # TODO: write tests for --enable-viewboxing
# 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