Fix bug when DOCTYPE is present. Big performance improvement to makeWellFormed() function
This commit is contained in:
parent
c835423e8f
commit
c00bc8b70c
5 changed files with 37 additions and 14 deletions
|
|
@ -13,11 +13,11 @@
|
||||||
<header>
|
<header>
|
||||||
<h2><a href="#0.24">Version 0.24</a></h2>
|
<h2><a href="#0.24">Version 0.24</a></h2>
|
||||||
</header>
|
</header>
|
||||||
<p>2010-02-04</p>
|
<p>2010-02-05</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/517064">Bug 517064</a> to make XML well-formed again</li>
|
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/517064">Bug 517064</a> to make XML well-formed again</li>
|
||||||
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/503750">Bug 503750</a> fix Inkscape extension to correctly pass --enable-viewboxing</li>
|
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/503750">Bug 503750</a> fix Inkscape extension to correctly pass --enable-viewboxing</li>
|
||||||
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/511186">Bug 511186</a> fix stripping of comments outside of the root <svg> node</li>
|
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/511186">Bug 511186</a> to allow comments outside of the root <svg> node</li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
||||||
23
scour.py
23
scour.py
|
|
@ -2021,15 +2021,17 @@ def remapNamespacePrefix(node, oldprefix, newprefix):
|
||||||
remapNamespacePrefix(child, oldprefix, newprefix)
|
remapNamespacePrefix(child, oldprefix, newprefix)
|
||||||
|
|
||||||
def makeWellFormed(str):
|
def makeWellFormed(str):
|
||||||
newstr = ''
|
|
||||||
xml_ents = { '<':'<', '>':'>', '&':'&', "'":''', '"':'"'}
|
xml_ents = { '<':'<', '>':'>', '&':'&', "'":''', '"':'"'}
|
||||||
for c in str:
|
|
||||||
if c in xml_ents:
|
# starr = []
|
||||||
newstr += xml_ents[c]
|
# for c in str:
|
||||||
else:
|
# if c in xml_ents:
|
||||||
newstr += c
|
# starr.append(xml_ents[c])
|
||||||
|
# else:
|
||||||
|
# starr.append(c)
|
||||||
|
|
||||||
return newstr
|
# this list comprehension is short-form for the above for-loop:
|
||||||
|
return ''.join([xml_ents[c] if c in xml_ents else c for c in str])
|
||||||
|
|
||||||
# hand-rolled serialization function that has the following benefits:
|
# hand-rolled serialization function that has the following benefits:
|
||||||
# - pretty printing
|
# - pretty printing
|
||||||
|
|
@ -2295,12 +2297,11 @@ def scourString(in_string, options=None):
|
||||||
else:
|
else:
|
||||||
total_output = ""
|
total_output = ""
|
||||||
|
|
||||||
# Find all comments before and after the root node and print them
|
|
||||||
for child in doc.childNodes:
|
for child in doc.childNodes:
|
||||||
if child.nodeType == 8:
|
if child.nodeType == 1:
|
||||||
total_output += ('<!--' + child.nodeValue + '-->' + os.linesep)
|
|
||||||
else:
|
|
||||||
total_output += "".join(lines)
|
total_output += "".join(lines)
|
||||||
|
else: # doctypes, entities, comments
|
||||||
|
total_output += child.toxml() + os.linesep
|
||||||
|
|
||||||
return total_output
|
return total_output
|
||||||
|
|
||||||
|
|
|
||||||
11
testscour.py
11
testscour.py
|
|
@ -996,7 +996,16 @@ class DoNotStripCommentsOutsideOfRoot(unittest.TestCase):
|
||||||
self.assertEquals( doc.childNodes[0].nodeType, 8, 'First node not a comment')
|
self.assertEquals( doc.childNodes[0].nodeType, 8, 'First node not a comment')
|
||||||
self.assertEquals( doc.childNodes[1].nodeType, 8, 'Second node not a comment')
|
self.assertEquals( doc.childNodes[1].nodeType, 8, 'Second node not a comment')
|
||||||
self.assertEquals( doc.childNodes[3].nodeType, 8, 'Fourth node not a comment')
|
self.assertEquals( doc.childNodes[3].nodeType, 8, 'Fourth node not a comment')
|
||||||
|
|
||||||
|
class DoNotStripDoctype(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
doc = scour.scourXmlFile('unittests/doctype.svg')
|
||||||
|
self.assertEquals( doc.childNodes.length, 3,
|
||||||
|
'Did not include the DOCROOT')
|
||||||
|
self.assertEquals( doc.childNodes[0].nodeType, 8, 'First node not a comment')
|
||||||
|
self.assertEquals( doc.childNodes[1].nodeType, 10, 'Second node not a doctype')
|
||||||
|
self.assertEquals( doc.childNodes[2].nodeType, 1, 'Third node not the root node')
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
||||||
6
unittests/comments.svg
Normal file
6
unittests/comments.svg
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" ?>
|
||||||
|
<!-- Empty -->
|
||||||
|
<!-- Comment #2 -->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
</svg>
|
||||||
|
<!-- After -->
|
||||||
|
After Width: | Height: | Size: 120 B |
7
unittests/doctype.svg
Normal file
7
unittests/doctype.svg
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- comment -->
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
|
||||||
|
<!ENTITY ns_svg "http://www.w3.org/2000/svg">
|
||||||
|
<!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
|
||||||
|
]>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"/>
|
||||||
|
After Width: | Height: | Size: 350 B |
Loading…
Add table
Add a link
Reference in a new issue