Commit 1270427f authored by Alec Mitchell's avatar Alec Mitchell

Fix bug in WebDAV/HEAD requests caused by traversal order change

parent b54e5b73
...@@ -8,6 +8,9 @@ Zope Changes ...@@ -8,6 +8,9 @@ Zope Changes
Bugs Fixed Bugs Fixed
- Traversal order changes were causing WebDAV requests which used
acquisition to fail.
- Collector #2157: Expose name of broken class in SystemError raised - Collector #2157: Expose name of broken class in SystemError raised
from '__getstate__' of a broken instance. from '__getstate__' of a broken instance.
......
...@@ -26,6 +26,7 @@ from Acquisition import Acquired, aq_inner, aq_parent, aq_base ...@@ -26,6 +26,7 @@ from Acquisition import Acquired, aq_inner, aq_parent, aq_base
from zExceptions import NotFound from zExceptions import NotFound
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from OFS.interfaces import ITraversable from OFS.interfaces import ITraversable
import webdav
from zope.interface import implements, Interface from zope.interface import implements, Interface
from zope.component import queryMultiAdapter from zope.component import queryMultiAdapter
...@@ -165,6 +166,7 @@ class Traversable: ...@@ -165,6 +166,7 @@ class Traversable:
else: else:
obj = self obj = self
resource = _marker
try: try:
while path: while path:
name = path_pop() name = path_pop()
...@@ -237,6 +239,13 @@ class Traversable: ...@@ -237,6 +239,13 @@ class Traversable:
else: else:
try: try:
next = obj[name] next = obj[name]
# The item lookup may return a NullResource,
# if this is the case we save it and return it
# if all other lookups fail.
if isinstance(next,
webdav.NullResource.NullResource):
resource = next
raise KeyError(name)
except AttributeError: except AttributeError:
# Raise NotFound for easier debugging # Raise NotFound for easier debugging
# instead of AttributeError: __getitem__ # instead of AttributeError: __getitem__
...@@ -267,6 +276,9 @@ class Traversable: ...@@ -267,6 +276,9 @@ class Traversable:
next = getattr(obj, name, _marker) next = getattr(obj, name, _marker)
except AttributeError: except AttributeError:
raise e raise e
if next is _marker:
# If we have a NullResource from earlier use it.
next = resource
if next is _marker: if next is _marker:
# Nothing found re-raise error # Nothing found re-raise error
raise e raise e
......
...@@ -597,6 +597,20 @@ def test_view_doesnt_shadow_attribute(): ...@@ -597,6 +597,20 @@ def test_view_doesnt_shadow_attribute():
>>> self.folder.ftf.unrestrictedTraverse('mouse')() >>> self.folder.ftf.unrestrictedTraverse('mouse')()
u'The mouse has been eaten by the eagle' u'The mouse has been eaten by the eagle'
Head requests have some unusual behavior in Zope 2, in particular, a failed
item lookup on an ObjectManager returns a NullResource, rather
than raising a KeyError. We need to make sure that this doesn't
result in acquired attributes being shadowed by the NullResource,
but that unknown names still give NullResources:
>>> self.app.REQUEST.maybe_webdav_client = True
>>> self.app.REQUEST['REQUEST_METHOD'] = 'HEAD'
>>> self.folder.ftf.unrestrictedTraverse('mouse')()
u'The mouse has been eaten by the eagle'
>>> self.folder.ftf.unrestrictedTraverse('nonsense')
<webdav.NullResource.NullResource object at ...>
Clean up: Clean up:
>>> from zope.app.testing.placelesssetup import tearDown >>> from zope.app.testing.placelesssetup import tearDown
......
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