[Zope-CVS] SVN: GenericSetup/trunk/ Fixed attribute quoting.
Florent Guillaume
fg at nuxeo.com
Mon Jan 30 11:18:34 EST 2006
Log message for revision 41496:
Fixed attribute quoting.
TAL.TALDefs.attrEscape is not suitable for bijective quoting/unquoting,
which is needed for proper I/O, as it leaves alone things that look
like well formed entities. Just use cgi.escape(s, quote=True).
Changed:
U GenericSetup/trunk/tests/test_utils.py
U GenericSetup/trunk/utils.py
-=-
Modified: GenericSetup/trunk/tests/test_utils.py
===================================================================
--- GenericSetup/trunk/tests/test_utils.py 2006-01-30 14:54:33 UTC (rev 41495)
+++ GenericSetup/trunk/tests/test_utils.py 2006-01-30 16:18:33 UTC (rev 41496)
@@ -371,23 +371,33 @@
class PrettyDocumentTests(unittest.TestCase):
def test_attr_quoting(self):
+ original = 'baz <bar>&"\''
+ expected = ('<?xml version="1.0"?>\n'
+ '<doc foo="baz &nbsp;<bar>&"\'"/>\n')
+
doc = PrettyDocument()
node = doc.createElement('doc')
- node.setAttribute('foo', 'baz <bar>&"'+"'")
+ node.setAttribute('foo', original)
doc.appendChild(node)
- self.assertEqual(doc.toprettyxml(' '),
- '<?xml version="1.0"?>\n'
- '<doc foo="baz <bar>&"'+"'"+'"/>\n')
+ self.assertEqual(doc.toprettyxml(' '), expected)
+ # Reparse
+ e = parseString(expected).documentElement
+ self.assertEqual(e.getAttribute('foo'), original)
def test_text_quoting(self):
+ original = 'goo <hmm>&"\''
+ expected = ('<?xml version="1.0"?>\n'
+ '<doc>goo &nbsp;<hmm>&"\'</doc>\n')
+
doc = PrettyDocument()
node = doc.createElement('doc')
- child = doc.createTextNode('goo <hmm>&"'+"'")
+ child = doc.createTextNode(original)
node.appendChild(child)
doc.appendChild(node)
- self.assertEqual(doc.toprettyxml(' '),
- '<?xml version="1.0"?>\n'
- '<doc>goo <hmm>&"'+"'</doc>\n")
+ self.assertEqual(doc.toprettyxml(' '), expected)
+ # Reparse
+ e = parseString(expected).documentElement
+ self.assertEqual(e.childNodes[0].nodeValue, original)
def test_suite():
# reimport to make sure tests are run from Products
Modified: GenericSetup/trunk/utils.py
===================================================================
--- GenericSetup/trunk/utils.py 2006-01-30 14:54:33 UTC (rev 41495)
+++ GenericSetup/trunk/utils.py 2006-01-30 16:18:33 UTC (rev 41496)
@@ -37,7 +37,6 @@
#BBB: for Zope 2.8
from Products.Five.bbb.OFS_interfaces import IOrderedContainer
from cgi import escape
-from TAL.TALDefs import attrEscape
from zope.app import zapi
from zope.interface import implements
from zope.interface import providedBy
@@ -362,7 +361,7 @@
for a_name in a_names:
wrapper.write()
- a_value = attrEscape(attrs[a_name].value)
+ a_value = escape(attrs[a_name].value, quote=True)
wrapper.queue(' %s="%s"' % (a_name, a_value))
if self.childNodes:
More information about the Zope-CVS
mailing list