Commit 45e5350a authored by Sidnei da Silva's avatar Sidnei da Silva

- Always unescape element contents on webdav.xmltools

      - Use saxutils to escape/unescape values for/from
        PROPFIND/PROPPATCH.

      - Make OFS.PropertySheet use the escaping function from
        webdav.xmltools.

      - Escape/unescape " and '

      - Set a default value of '' for the new 'alt' property as not to
        break existing content.
parent df259636
...@@ -38,12 +38,25 @@ Zope Changes ...@@ -38,12 +38,25 @@ Zope Changes
'alt' property. The border="0" attribute is no longer part of the HTML 'alt' property. The border="0" attribute is no longer part of the HTML
output except specified otherwise. output except specified otherwise.
- Set a default value of '' for the new 'alt' property as not to
break existing content.
- Collector #1511: made IPCServer show up in the Control Panel under - Collector #1511: made IPCServer show up in the Control Panel under
"Network Services" "Network Services"
- Collector #1443: Applied patch by Simon Eisenmann that reimplements - Collector #1443: Applied patch by Simon Eisenmann that reimplements
the XML parser used in WebDAV fixing a memory leak. the XML parser used in WebDAV fixing a memory leak.
- Always unescape element contents on webdav.xmltools
- Use saxutils to escape/unescape values for/from
PROPFIND/PROPPATCH.
- Make OFS.PropertySheet use the escaping function from
webdav.xmltools.
- Escape/unescape " and '
Zope 2.8a1 Zope 2.8a1
......
...@@ -76,6 +76,7 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -76,6 +76,7 @@ class File(Persistent, Implicit, PropertyManager,
precondition='' precondition=''
size=None size=None
alt=''
manage_editForm =DTMLFile('dtml/fileEdit',globals(), manage_editForm =DTMLFile('dtml/fileEdit',globals(),
Kind='File',kind='file') Kind='File',kind='file')
......
...@@ -807,15 +807,12 @@ def absattr(attr): ...@@ -807,15 +807,12 @@ def absattr(attr):
return attr() return attr()
return attr return attr
def xml_escape(value):
def xml_escape(v): from webdav.xmltools import escape
""" convert any content from ISO-8859-1 to UTF-8 if not isinstance(value, basestring):
The main use is to escape non-US object property values value = unicode(value)
(e.g. containing accented characters). Also we convert "<" and ">" if not isinstance(value, unicode):
to entities to keep the properties XML compliant. # XXX It really shouldn't be hardcoded to latin-1 here.
""" value = value.decode('latin-1')
v = str(v) value = escape(value)
v = v.replace('&', '&amp;') return value.encode('utf-8')
v = v.replace('<', '&lt;')
v = v.replace('>', '&gt;')
return unicode(v,"latin-1").encode("utf-8")
...@@ -10,13 +10,10 @@ ...@@ -10,13 +10,10 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
""" """
WebDAV XML request parsing tool using xml.minidom as xml parser. WebDAV XML request parsing tool using xml.minidom as xml parser.
Code contributed by Simon Eisenmann, struktur AG, Stuttgart, Germany Code contributed by Simon Eisenmann, struktur AG, Stuttgart, Germany
""" """
__version__='$Revision: 1.15.2.1 $'[11:-2] __version__='$Revision: 1.15.2.1 $'[11:-2]
""" """
...@@ -33,9 +30,39 @@ TODO: ...@@ -33,9 +30,39 @@ TODO:
""" """
from xml.dom import minidom from xml.dom import minidom
from xml.sax.saxutils import escape as _escape, unescape as _unescape
escape_entities = {'"': '&quot;',
"'": '&apos;',
}
unescape_entities = {'&quot;': '"',
'&apos;': "'",
}
def escape(value, entities=None):
_ent = escape_entities
if entities is not None:
_ent = _ent.copy()
_ent.update(entities)
return _escape(value, entities)
def unescape(value, entities=None):
_ent = unescape_entities
if entities is not None:
_ent = _ent.copy()
_ent.update(entities)
return _unescape(value, entities)
# XXX latin-1 is hardcoded on OFS.PropertySheets as the expected
# encoding properties will be stored in. Optimally, we should use the
# same encoding as the 'default_encoding' property that is used for
# the ZMI.
zope_encoding = 'latin-1'
class Node: class Node:
""" our nodes no matter what type """ """ Our nodes no matter what type
"""
node = None node = None
...@@ -43,9 +70,12 @@ class Node: ...@@ -43,9 +70,12 @@ class Node:
self.node=node self.node=node
def elements(self, name=None, ns=None): def elements(self, name=None, ns=None):
nodes=[ Node(n) for n in self.node.childNodes if n.nodeType == n.ELEMENT_NODE and \ nodes = []
((name is None) or ((n.localName.lower())==name)) and \ for n in self.node.childNodes:
((ns is None) or (n.namespaceURI==ns)) ] if (n.nodeType == n.ELEMENT_NODE and
((name is None) or ((n.localName.lower())==name)) and
((ns is None) or (n.namespaceURI==ns))):
nodes.append(Element(n))
return nodes return nodes
def qname(self): def qname(self):
...@@ -59,7 +89,7 @@ class Node: ...@@ -59,7 +89,7 @@ class Node:
return self.node.toxml() return self.node.toxml()
def strval(self): def strval(self):
return self.toxml() return self.toxml().encode(zope_encoding)
def name(self): return self.node.localName def name(self): return self.node.localName
def attrs(self): return self.node.attributes def attrs(self): return self.node.attributes
...@@ -87,9 +117,23 @@ class Node: ...@@ -87,9 +117,23 @@ class Node:
return "<Node %s (from %s)>" % (self.name(), self.namespace()) return "<Node %s (from %s)>" % (self.name(), self.namespace())
else: return "<Node %s>" % self.name() else: return "<Node %s>" % self.name()
class Element(Node):
def toxml(self):
# When dealing with Elements, we only want the Element's content.
result = u''
for n in self.node.childNodes:
value = n.toxml()
# Use unescape possibly escaped values. We do this
# because the value is *always* escaped in it's XML
# representation, and if we store it escaped it will come
# out *double escaped* when doing a PROPFIND.
value = unescape(value, entities=unescape_entities)
result += value
return result
class XmlParser: class XmlParser:
""" simple wrapper around minidom to support the required """ Simple wrapper around minidom to support the required
interfaces for zope.webdav interfaces for zope.webdav
""" """
...@@ -99,6 +143,5 @@ class XmlParser: ...@@ -99,6 +143,5 @@ class XmlParser:
pass pass
def parse(self, data): def parse(self, data):
self.dom=minidom.parseString(data) self.dom = minidom.parseString(data)
return Node(self.dom) return Node(self.dom)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment