Commit 0e9e7a53 authored by Chris McDonough's avatar Chris McDonough

Tests 15 (propnullns) and 16 (propget) from the props suite

of litmus version 10.5 (http://www.webdav.org/neon/litmus/)
expose a bug in Zope propertysheet access via DAV.  If a
proppatch command sets a property with a null xmlns,
e.g. with a PROPPATCH body like:

<?xml version="1.0" encoding="utf-8" ?>
<propertyupdate xmlns="DAV:">
<set>
<prop>
 <nonamespace xmlns="">randomvalue</nonamespace>
</prop>
</set>
</propertyupdate>

When we set properties in the null namespace, Zope turns
around and creates (or finds) a propertysheet with the
xml_namespace of None and sets the value on it.  The
response to a subsequent PROPFIND for the resource will fail
because the XML generated by dav__propstat included a bogus
namespace declaration (xmlns="None").

Fixed by amending OFS.PropertySheets.dav__propstat.
parent ad8cd56a
...@@ -97,6 +97,11 @@ Zope Changes ...@@ -97,6 +97,11 @@ Zope Changes
Bugs Fixed Bugs Fixed
- When Zope properties were set via DAV in the "null" namespace
(xmlns="") a subsequent PROPFIND for the property would cause the
XML representation for that property to show a namespace of
xmlns="None". Fixed within OFS.PropertySheets.dav__propstat.
- Relaxed requirements for context of - Relaxed requirements for context of
Products.Five.browser.pagetemplatefile.ZopeTwoPageTemplateFile, Products.Five.browser.pagetemplatefile.ZopeTwoPageTemplateFile,
to reduce barriers for testing renderability of views which use them. to reduce barriers for testing renderability of views which use them.
......
...@@ -363,7 +363,10 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -363,7 +363,10 @@ class PropertySheet(Traversable, Persistent, Implicit):
xml_id=self.xml_namespace() xml_id=self.xml_namespace()
propdict=self._propdict() propdict=self._propdict()
if not propdict.has_key(name): if not propdict.has_key(name):
prop='<n:%s xmlns:n="%s"/>\n' % (name, xml_id) if xml_id:
prop='<n:%s xmlns:n="%s"/>\n' % (name, xml_id)
else:
prop='<%s xmlns=""/>\n' % name
code='404 Not Found' code='404 Not Found'
if not result.has_key(code): if not result.has_key(code):
result[code]=[prop] result[code]=[prop]
...@@ -388,8 +391,12 @@ class PropertySheet(Traversable, Persistent, Implicit): ...@@ -388,8 +391,12 @@ class PropertySheet(Traversable, Persistent, Implicit):
attrs='' attrs=''
if not hasattr(self, 'dav__%s' % name): if not hasattr(self, 'dav__%s' % name):
value = xml_escape(value) value = xml_escape(value)
prop='<n:%s%s xmlns:n="%s">%s</n:%s>\n' % ( if xml_id:
name, attrs, xml_id, value, name) prop='<n:%s%s xmlns:n="%s">%s</n:%s>\n' % (
name, attrs, xml_id, value, name)
else:
prop ='<%s%s xmlns="">%s</%s>\n' % (
name, attrs, value, name)
code='200 OK' code='200 OK'
if not result.has_key(code): if not result.has_key(code):
result[code]=[prop] result[code]=[prop]
......
...@@ -76,6 +76,50 @@ class TestPropertySheet(unittest.TestCase): ...@@ -76,6 +76,50 @@ class TestPropertySheet(unittest.TestCase):
self.failUnless(type(inst.getProperty('prop2')) == type(())) self.failUnless(type(inst.getProperty('prop2')) == type(()))
self.failUnless(type(inst.prop2) == type(())) self.failUnless(type(inst.prop2) == type(()))
def test_dav__propstat_nullns(self):
# Tests 15 (propnullns) and 16 (propget) from the props suite
# of litmus version 10.5 (http://www.webdav.org/neon/litmus/)
# expose a bug in Zope propertysheet access via DAV. If a
# proppatch command sets a property with a null xmlns,
# e.g. with a PROPPATCH body like:
#
# <?xml version="1.0" encoding="utf-8" ?>
# <propertyupdate xmlns="DAV:">
# <set>
# <prop>
# <nonamespace xmlns="">randomvalue</nonamespace>
# </prop>
# </set>
# </propertyupdate>
#
# When we set properties in the null namespace, Zope turns
# around and creates (or finds) a propertysheet with the
# xml_namespace of None and sets the value on it. The
# response to a subsequent PROPFIND for the resource will fail
# because the XML generated by dav__propstat included a bogus
# namespace declaration (xmlns="None").
#
inst = self._makeOne('foo')
inst._md = {'xmlns':None}
resultd = {}
inst._setProperty('foo', 'bar')
inst.dav__propstat('foo', resultd)
self.assertEqual(len(resultd['200 OK']), 1)
self.assertEqual(resultd['200 OK'][0], '<foo xmlns="">bar</foo>\n')
def test_dav__propstat_notnullns(self):
# see test_dav__propstat_nullns
inst = self._makeOne('foo')
inst._md = {'xmlns':'http://www.example.com/props'}
resultd = {}
inst._setProperty('foo', 'bar')
inst.dav__propstat('foo', resultd)
self.assertEqual(len(resultd['200 OK']), 1)
self.assertEqual(resultd['200 OK'][0],
'<n:foo xmlns:n="http://www.example.com/props">bar'
'</n:foo>\n')
def test_suite(): def test_suite():
return unittest.TestSuite(( return unittest.TestSuite((
......
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