Commit 14b41ba5 authored by Christian Theune's avatar Christian Theune

Fix #118088: Moving a folder to one of its subfolders causes a system error.

parent 88c4e395
...@@ -5,6 +5,8 @@ CHANGES ...@@ -5,6 +5,8 @@ CHANGES
3.11.2 (unreleased) 3.11.2 (unreleased)
------------------- -------------------
- Fix detection of moving folders into itself or a subfolder of itself.
(#118088)
3.11.1 (2010-04-30) 3.11.1 (2010-04-30)
------------------- -------------------
......
...@@ -159,7 +159,7 @@ from zope.container.i18n import ZopeMessageFactory as _ ...@@ -159,7 +159,7 @@ from zope.container.i18n import ZopeMessageFactory as _
from zope.container.interfaces import IContainer from zope.container.interfaces import IContainer
def checkObject(container, name, object): def checkObject(container, name, object):
"""Check containement constraints for an object and container """Check containment constraints for an object and container
""" """
# check __setitem__ precondition # check __setitem__ precondition
...@@ -170,6 +170,16 @@ def checkObject(container, name, object): ...@@ -170,6 +170,16 @@ def checkObject(container, name, object):
if precondition is not None: if precondition is not None:
precondition(container, name, object) precondition(container, name, object)
# check that object is not being pasted into itself or its children.
target = container
while target is not None:
if target is object:
raise TypeError("Cannot add an object to itself or its children.")
if zope.location.interfaces.ILocation.providedBy(target):
target = target.__parent__
else:
target = None
# check the constraint on __parent__ # check the constraint on __parent__
__parent__ = providedBy(object).get('__parent__') __parent__ = providedBy(object).get('__parent__')
if __parent__ is not None: if __parent__ is not None:
......
...@@ -96,4 +96,20 @@ could have defined these in the opposite order: ...@@ -96,4 +96,20 @@ could have defined these in the opposite order:
>>> checkFactory(Contacts(), 'x', Factory(Buddy)) >>> checkFactory(Contacts(), 'x', Factory(Buddy))
False False
The constraints prevent us from moving a container beneath itself (either into
itself or another folder beneath it):
>>> container = Container()
>>> checkObject(container, 'x', container)
Traceback (most recent call last):
TypeError: Cannot add an object to itself or its children.
>>> import zope.location.interfaces
>>> import zope.interface
>>> subcontainer = Container()
>>> zope.interface.directlyProvides(subcontainer,
... zope.location.interfaces.ILocation)
>>> subcontainer.__parent__ = container
>>> checkObject(subcontainer, 'x', container)
Traceback (most recent call last):
TypeError: Cannot add an object to itself or its children.
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