Hi,

If an object with a unicode name is copied then deleted, there is a unicode error. I've reported it here:
https://bugs.launchpad.net/zope3/+bug/238579

This is annoying because the user account becomes unusable!

The deleted object is kept in the user's clipboard, and the traversal is tried evereytime a folder is viewed, to check if the object is pasteable().
The ContainerTraversable adapter tries to gettattr with a unicode name.

I've attached a patch with unittest + ftest + fix. Could you please check this is the right place or the right way to fix it? If this is ok, I will commit the fix.

regards,
Christophe

Index: zope/app/container/browser/tests/test_contents_functional.py
===================================================================
--- zope/app/container/browser/tests/test_contents_functional.py        
(révision 87253)
+++ zope/app/container/browser/tests/test_contents_functional.py        (copie 
de travail)
@@ -337,7 +337,31 @@
         body = response.getBody()
         self.assert_("cannot be moved" in body)
 
+    def test_copy_then_delete_with_unicode_name(self):
+        """Tests unicode on object copied then deleted (#238579)."""
 
+        # create a file with an accentuated unicode name
+        root = self.getRootFolder()
+        root[u'voil\xe0'] = File()
+        transaction.commit()
+
+        # copy the object
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw', form={
+            'ids' : (u'voil\xe0',),
+            'container_copy_button' : '' })
+        self.assertEqual(response.getStatus(), 302)
+        self.assertEqual(response.getHeader('Location'),
+            'http://localhost/@@contents.html')
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+
+        # delete the object
+        del root[u'voil\xe0']
+        transaction.commit()
+        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
+        self.assertEqual(response.getStatus(), 200)
+
+
 def test_suite():
     suite = unittest.TestSuite()
     Test.layer = AppContainerLayer
Index: zope/app/container/traversal.py
===================================================================
--- zope/app/container/traversal.py     (révision 87253)
+++ zope/app/container/traversal.py     (copie de travail)
@@ -95,7 +95,10 @@
 
         v = container.get(name, _marker)
         if v is _marker:
-            v = getattr(container, name, _marker)
+            try:
+                v = getattr(container, name, _marker)
+            except UnicodeEncodeError:
+                raise TraversalError(container, name)
             if v is _marker:
                 raise TraversalError(container, name)
 
Index: zope/app/container/tests/test_containertraversable.py
===================================================================
--- zope/app/container/tests/test_containertraversable.py       (révision 
87253)
+++ zope/app/container/tests/test_containertraversable.py       (copie de 
travail)
@@ -59,6 +59,11 @@
         self.failUnless(T.traverse('bar', []) is bar)
 
         self.assertRaises(TraversalError , T.traverse, 'morebar', [])
+    def test_unicode_attr(self):
+        # test traversal with unicode
+        voila = Container()
+        c   = Container({}, {u'voil\xe0': voila})
+        self.failUnless(ContainerTraversable(c).traverse(u'voil\xe0', []) is 
voila)
 
 
 def test_suite():
_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to