Fix Bug 517064: Make XML well-formed again by properly translating the 5 XML entities
This commit is contained in:
parent
6230682a01
commit
6147bb2085
4 changed files with 28 additions and 19 deletions
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
SCOURVER="0.23"
|
||||
SCOURVER="0.24"
|
||||
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
|
||||
cd scour
|
||||
|
|
|
|||
|
|
@ -9,11 +9,21 @@
|
|||
|
||||
<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">
|
||||
<header>
|
||||
<h2><a href="#0.23">Version 0.23</a></h2>
|
||||
</header>
|
||||
<p>2009-01-04</p>
|
||||
<p>2010-01-04</p>
|
||||
<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 unittests to run properly in Windows</li>
|
||||
|
|
|
|||
26
scour.py
26
scour.py
|
|
@ -72,7 +72,7 @@ except ImportError:
|
|||
pass
|
||||
|
||||
APP = 'scour'
|
||||
VER = '0.23'
|
||||
VER = '0.24'
|
||||
COPYRIGHT = 'Copyright Jeff Schiller, 2010'
|
||||
|
||||
NS = { 'SVG': 'http://www.w3.org/2000/svg',
|
||||
|
|
@ -2021,19 +2021,13 @@ def remapNamespacePrefix(node, oldprefix, newprefix):
|
|||
remapNamespacePrefix(child, oldprefix, newprefix)
|
||||
|
||||
def makeWellFormed(str):
|
||||
newstr = str
|
||||
|
||||
# encode & as & ( must do this first so that < does not become &lt; )
|
||||
if str.find('&') != -1:
|
||||
newstr = str.replace('&', '&')
|
||||
|
||||
# encode < as <
|
||||
if str.find("<") != -1:
|
||||
newstr = str.replace('<', '<')
|
||||
|
||||
# encode > as > (TODO: is this necessary?)
|
||||
if str.find('>') != -1:
|
||||
newstr = str.replace('>', '>')
|
||||
newstr = ''
|
||||
xml_ents = { '<':'<', '>':'>', '&':'&', "'":''', '"':'"'}
|
||||
for c in str:
|
||||
if c in xml_ents:
|
||||
newstr += xml_ents[c]
|
||||
else:
|
||||
newstr += c
|
||||
|
||||
return newstr
|
||||
|
||||
|
|
@ -2278,7 +2272,7 @@ def scourString(in_string, options=None):
|
|||
embedRasters(elem, options)
|
||||
|
||||
# properly size the SVG document (ideally width/height should be 100% with a viewBox)
|
||||
if options.viewboxing:
|
||||
if options.enable_viewboxing:
|
||||
properlySizeDoc(doc.documentElement)
|
||||
|
||||
# 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,
|
||||
help="won't output the <?xml ?> prolog")
|
||||
_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")
|
||||
|
||||
# GZ: this is confusing, most people will be thinking in terms of
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class ScourOptions:
|
|||
keep_editor_data = False
|
||||
strip_xml_prolog = False
|
||||
indent_type = "space"
|
||||
viewboxing = False
|
||||
enable_viewboxing = False
|
||||
|
||||
class NoInkscapeElements(unittest.TestCase):
|
||||
def runTest(self):
|
||||
|
|
@ -983,6 +983,11 @@ class EnsureLineEndings(unittest.TestCase):
|
|||
self.assertEquals( len(s.splitlines()), 4,
|
||||
'Did not output line ending character correctly')
|
||||
|
||||
class XmlEntities(unittest.TestCase):
|
||||
def runTest(self):
|
||||
self.assertEquals( scour.makeWellFormed('<>&"\''), '<>&"'',
|
||||
'Incorrectly translated XML entities')
|
||||
|
||||
# TODO: write tests for --enable-viewboxing
|
||||
# TODO; write a test for embedding rasters
|
||||
# TODO: write a test for --disable-embed-rasters
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue