Commit 61002ca7 authored by Chris McDonough's avatar Chris McDonough

litmus props tests 19: propvalnspace and 20:

propwformed were failing because Zope did not strip off the
xmlns: attribute attached to XML property values.  We now strip
off all attributes that look like xmlns declarations.
parent ccc4a377
......@@ -97,6 +97,11 @@ Zope Changes
Bugs Fixed
- DAV: litmus props tests 19: propvalnspace and 20:
propwformed were failing because Zope did not strip off the
xmlns: attribute attached to XML property values. We now strip
off all attributes that look like xmlns declarations.
- DAV: When a client attempted to unlock a resource with a token
that the resource hadn't been locked with, in the past we
returned a 204 response. This was incorrect. The "correct"
......
......@@ -219,8 +219,7 @@ class PropPatch:
else:
# xml property
attrs={}
prop.remap({ns:'n'})
prop.del_attr('xmlns:n')
prop.remove_namespace_attrs()
for attr in prop.attrs():
attrs[attr.qname()]=attr.value()
md={'__xml_attrs__':attrs}
......
......@@ -56,9 +56,45 @@ class TestUnlock(unittest.TestCase):
result.find('<d:status>HTTP/1.1 400 Bad Request</d:status>'),
-1)
class TestPropPatch(unittest.TestCase):
def _getTargetClass(self):
from webdav.davcmds import PropPatch
return PropPatch
def _makeOne(self, request):
klass = self._getTargetClass()
return klass(request)
def test_parse_xml_property_values_with_namespaces(self):
"""
Before Zope 2.11, litmus props tests 19: propvalnspace and 20:
propwformed were failing because Zope did not strip off the
xmlns: attribute attached to XML property values. We now strip
off all attributes that look like xmlns declarations.
"""
reqbody = """<?xml version="1.0" encoding="utf-8" ?>
<propertyupdate xmlns='DAV:'>
<set>
<prop>
<t:valnspace xmlns:t='http://webdav.org/neon/litmus/'>
<foo xmlns='bar'/>
</t:valnspace>
</prop>
</set>
</propertyupdate>"""
request = {'BODY':reqbody}
inst = self._makeOne(request)
self.assertEqual(len(inst.values), 1)
self.assertEqual(inst.values[0][3]['__xml_attrs__'], {})
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestUnlock),
unittest.makeSuite(TestPropPatch),
))
if __name__ == '__main__':
......
import unittest
class TestNode(unittest.TestCase):
def _getTargetClass(self):
from webdav.xmltools import Node
return Node
def _makeOne(self, wrapped):
klass = self._getTargetClass()
return klass(wrapped)
def test_remove_namespace_attrs(self):
""" A method added in Zope 2.11 which removes any attributes
which appear to be XML namespace declarations """
class DummyMinidomNode:
def __init__(self):
self.attributes = {'xmlns:foo':'foo', 'xmlns':'bar', 'a':'b'}
def hasAttributes(self):
return True
def removeAttribute(self, name):
del self.attributes[name]
wrapped = DummyMinidomNode()
node = self._makeOne(wrapped)
node.remove_namespace_attrs()
self.assertEqual(wrapped.attributes, {'a':'b'})
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestNode),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
......@@ -107,6 +107,19 @@ class Node:
def attrs(self):
return [Node(n) for n in self.node.attributes.values()]
def remove_namespace_attrs(self):
# remove all attributes which start with "xmlns:" or
# are equal to "xmlns"
if self.node.hasAttributes():
toremove = []
for name, value in self.node.attributes.items():
if name.startswith('xmlns:'):
toremove.append(name)
if name == 'xmlns':
toremove.append(name)
for name in toremove:
self.node.removeAttribute(name)
def del_attr(self, name):
# NOTE: zope calls this after remapping to remove namespace
# zope passes attributes like xmlns:n
......
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