Fix prefixing namespace prefix declarations when not using the default namespace (XML serialization bug)

This commit is contained in:
JSCHILL1 2009-08-12 09:49:22 -05:00
parent eb2a7a05ac
commit d4747e2bd7
5 changed files with 51 additions and 13 deletions

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
SCOURVER="0.18" SCOURVER="0.19"
cd .. cd ..
zip scour/tarballs/scour-$SCOURVER.zip 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
cd scour cd scour

View file

@ -53,17 +53,17 @@
# </g> # </g>
# Next Up: # Next Up:
# + Remove some attributes that have default values # - analyze all children of a group, if they have common attributes, then move them to the group
# + Convert c/q path segments into shorthand equivalents where possible: # - analyze a group and its children, if a group's attribute is not being used by any children
# + custom serialization of SVG that prints out id/xml:id first (suggestion by Richard Hutch) # (or descendants?) then remove it
# + --indent option to specify how indent should work: space, tab, none # - crunch *opacity, offset values (remove trailing zeros, reduce prec, integerize)
# - option to remove metadata # - add an option to remove ids if they match the Inkscape-style of IDs
# - investigate point-reducing algorithms
# - parse transform attribute # - parse transform attribute
# - if a <g> has only one element in it, collapse the <g> (ensure transform, etc are carried down) # - if a <g> has only one element in it, collapse the <g> (ensure transform, etc are carried down)
# - remove id if it matches the Inkscape-style of IDs (also provide a switch to disable this) # - option to remove metadata
# - prevent elements from being stripped if they are referenced in a <style> element # - prevent elements from being stripped if they are referenced in a <style> element
# (for instance, filter, marker, pattern) - need a crude CSS parser # (for instance, filter, marker, pattern) - need a crude CSS parser
# - Remove any unused glyphs from font elements?
# - add an option for svgweb compatible markup (no self-closing tags)? # - add an option for svgweb compatible markup (no self-closing tags)?
# necessary to get true division # necessary to get true division
@ -88,7 +88,7 @@ except ImportError:
Decimal = FixedPoint Decimal = FixedPoint
APP = 'scour' APP = 'scour'
VER = '0.18' VER = '0.19'
COPYRIGHT = 'Copyright Jeff Schiller, 2009' COPYRIGHT = 'Copyright Jeff Schiller, 2009'
NS = { 'SVG': 'http://www.w3.org/2000/svg', NS = { 'SVG': 'http://www.w3.org/2000/svg',
@ -1931,7 +1931,11 @@ def serializeXML(element, options, ind = 0):
attrValue = makeWellFormed( attr.nodeValue ) attrValue = makeWellFormed( attr.nodeValue )
outString += ' ' + attr.nodeName + '=' + quot + attrValue + quot outString += ' '
# preserve xmlns: if it is a namespace prefix declaration
if attr.namespaceURI == 'http://www.w3.org/2000/xmlns/' and attr.nodeName.find('xmlns') == -1:
outString += 'xmlns:'
outString += attr.nodeName + '=' + quot + attrValue + quot
# if no children, self-close # if no children, self-close
children = element.childNodes children = element.childNodes

View file

@ -857,6 +857,11 @@ class WellFormedXMLAmpersandInTextContent(unittest.TestCase):
self.assert_( wellformed.find('<desc>Peanut Butter &amp; Jelly</desc>') != -1, self.assert_( wellformed.find('<desc>Peanut Butter &amp; Jelly</desc>') != -1,
'Improperly serialized &amp; in text content') 'Improperly serialized &amp; in text content')
class NamespaceDeclPrefixesInXML(unittest.TestCase):
def runTest(self):
xmlstring = scour.scourString(open('unittests/xml-ns-decl.svg').read())
self.assert_( xmlstring.find('xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"') != -1,
'Improperly serialized namespace prefix declarations')
# 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

29
unittests/xml-ns-decl.svg Normal file
View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://creativecommons.org/ns#" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:RDF id="RDF5">
<cc:Work id="Work6" rdf:about="">
<dc:format id="format7">image/svg+xml</dc:format>
<dc:type id="type9" rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title id="title6241">Open Clip Art Logo</dc:title>
<dc:date id="date6243">10-01-2004</dc:date>
<dc:creator id="creator6245">
<cc:Agent id="Agent6246">
<dc:title id="title6247">Andreas Nilsson</dc:title>
</cc:Agent>
</dc:creator>
<cc:license id="license6249" rdf:resource="http://web.resource.org/cc/PublicDomain"/>
<dc:contributor id="contributor6254">
<cc:Agent id="Agent6255">
<dc:title id="title6256">Jon Phillips, Tobias Jakobs</dc:title>
</cc:Agent>
</dc:contributor>
<dc:description id="description6258">This is one version of the official Open Clip Art Library logo.</dc:description>
<dc:subject id="subject6260">logo, open clip art library logo, logotype</dc:subject>
</cc:Work>
<cc:License id="License6250" rdf:about="http://web.resource.org/cc/PublicDomain">
<cc:permits id="permits6251" rdf:resource="http://web.resource.org/cc/Reproduction"/>
<cc:permits id="permits6252" rdf:resource="http://web.resource.org/cc/Distribution"/>
<cc:permits id="permits6253" rdf:resource="http://web.resource.org/cc/DerivativeWorks"/>
</cc:License>
</rdf:RDF>
</svg:svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:foo="http://foo/">
<!-- &lt;Jack &amp; Jill&gt; --> <!-- &lt;Jack &amp; Jill&gt; -->
<title>2 &lt; 5</title> <title>2 &lt; 5</title>
<desc>Peanut Butter &amp; Jelly</desc> <desc>Peanut Butter &amp; Jelly</desc>

Before

Width:  |  Height:  |  Size: 320 B

After

Width:  |  Height:  |  Size: 344 B

Before After
Before After