Commit fe1a94fd authored by Christophe Combelles's avatar Christophe Combelles

- fixed #227617 :

    - prevent the namechooser from failing on '+', '@' and '/'
    - added tests in the namechooser
    - be sure the name chooser returns unicode
parent 3ac502d9
......@@ -7,6 +7,11 @@ CHANGES
- fixed #238579 / #163149: error with unicode traversing
- fixed #221025 : adding menu is sorted with translated item
- fixed #227617 :
- prevent the namechooser from failing on '+', '@' and '/'
- added tests in the namechooser
- be sure the name chooser returns unicode
3.6.0 (2008-05-06)
------------------
......
......@@ -86,7 +86,6 @@ class BTreeContainer(SampleContainer, Persistent):
return l
def __len__(self):
#import pdb;pdb.set_trace()
return self.__len()
def __setitem__(self, key, value):
......
......@@ -705,7 +705,45 @@ class NameChooser(object):
self.context = context
def checkName(self, name, object):
"See zope.app.container.interfaces.INameChooser"
"""See zope.app.container.interfaces.INameChooser
We create and populate a dummy container
>>> from zope.app.container.sample import SampleContainer
>>> container = SampleContainer()
>>> container['foo'] = 'bar'
>>> from zope.app.container.contained import NameChooser
All these names are invalid:
>>> NameChooser(container).checkName('+foo', object())
Traceback (most recent call last):
...
UserError: Names cannot begin with '+' or '@' or contain '/'
>>> NameChooser(container).checkName('@foo', object())
Traceback (most recent call last):
...
UserError: Names cannot begin with '+' or '@' or contain '/'
>>> NameChooser(container).checkName('f/oo', object())
Traceback (most recent call last):
...
UserError: Names cannot begin with '+' or '@' or contain '/'
>>> NameChooser(container).checkName('foo', object())
Traceback (most recent call last):
...
UserError: The given name is already being used
>>> NameChooser(container).checkName(2, object())
Traceback (most recent call last):
...
TypeError: ('Invalid name type', <type 'int'>)
This one is ok:
>>> NameChooser(container).checkName('2', object())
True
"""
if not name:
raise UserError(
......@@ -731,13 +769,36 @@ class NameChooser(object):
def chooseName(self, name, object):
"See zope.app.container.interfaces.INameChooser"
"""See zope.app.container.interfaces.INameChooser
The name chooser is expected to choose a name without error
We create and populate a dummy container
>>> from zope.app.container.sample import SampleContainer
>>> container = SampleContainer()
>>> container['foo.old.rst'] = 'rst doc'
>>> from zope.app.container.contained import NameChooser
>>> NameChooser(container).chooseName('+@+@foo.old.rst', object())
u'foo.old-2.rst'
>>> NameChooser(container).chooseName('+@+@foo/foo', object())
u'foo-foo'
>>> NameChooser(container).chooseName('', object())
u'object'
>>> NameChooser(container).chooseName('@+@', object())
u'object'
"""
container = self.context
if not name:
name = object.__class__.__name__
# remove characters that checkName does not allow
name = unicode(name.replace('/', '-').lstrip('+@'))
if not name:
name = unicode(object.__class__.__name__)
dot = name.rfind('.')
if dot >= 0:
suffix = name[dot:]
......
......@@ -287,7 +287,8 @@ class INameChooser(Interface):
"""
def chooseName(name, object):
"""Choose a unique valid name for the object
"""Choose a unique valid name for the object.
This method is expected to always choose a valid name without error.
The given name and object may be taken into account when
choosing the name.
......
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