[Zope-Checkins] SVN: Zope/trunk/ Tests 15 (propnullns) and 16 (propget) from the props suite

Chris McDonough chrism at plope.com
Sat Jun 16 16:37:34 EDT 2007


Log message for revision 76721:
  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.
  
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/OFS/PropertySheets.py
  U   Zope/trunk/lib/python/OFS/tests/testProperties.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2007-06-16 11:40:18 UTC (rev 76720)
+++ Zope/trunk/doc/CHANGES.txt	2007-06-16 20:37:33 UTC (rev 76721)
@@ -97,6 +97,11 @@
 
     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
         Products.Five.browser.pagetemplatefile.ZopeTwoPageTemplateFile,
         to reduce barriers for testing renderability of views which use them.

Modified: Zope/trunk/lib/python/OFS/PropertySheets.py
===================================================================
--- Zope/trunk/lib/python/OFS/PropertySheets.py	2007-06-16 11:40:18 UTC (rev 76720)
+++ Zope/trunk/lib/python/OFS/PropertySheets.py	2007-06-16 20:37:33 UTC (rev 76721)
@@ -363,7 +363,10 @@
         xml_id=self.xml_namespace()
         propdict=self._propdict()
         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'
             if not result.has_key(code):
                 result[code]=[prop]
@@ -388,8 +391,12 @@
                 attrs=''
                 if not hasattr(self, 'dav__%s' % name):
                     value = xml_escape(value)
-            prop='<n:%s%s xmlns:n="%s">%s</n:%s>\n' % (
-                name, attrs, xml_id, value, name)
+            if xml_id:
+                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'
             if not result.has_key(code):
                 result[code]=[prop]

Modified: Zope/trunk/lib/python/OFS/tests/testProperties.py
===================================================================
--- Zope/trunk/lib/python/OFS/tests/testProperties.py	2007-06-16 11:40:18 UTC (rev 76720)
+++ Zope/trunk/lib/python/OFS/tests/testProperties.py	2007-06-16 20:37:33 UTC (rev 76721)
@@ -76,7 +76,51 @@
         self.failUnless(type(inst.getProperty('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():
     return unittest.TestSuite((
         unittest.makeSuite(TestPropertyManager),



More information about the Zope-Checkins mailing list