Skip to content

Commit

Permalink
Merge pull request #42 from zopefoundation/issue41
Browse files Browse the repository at this point in the history
Fix multiple leading dots in GlobalObject/Interface.
  • Loading branch information
jamadden committed Sep 27, 2018
2 parents 722d905 + 23f7ab3 commit 4083b7b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changes
4.2.2 (unreleased)
------------------

- Nothing changed yet.
- Fix ``GlobalObject`` (and ``GlobalInterface``) no longer allowing
multiple leading dots. See `issue 41
<https://github.com/zopefoundation/zope.configuration/issues/41>`_.


4.2.1 (2018-09-26)
Expand Down
2 changes: 1 addition & 1 deletion src/zope/configuration/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def fromUnicode(self, value):
# package, but not accepted by DottedName. Take care,
# though, because a single dot is valid to resolve, but
# not valid to pass to DottedName (as an empty string)
to_validate = name[1:] if name.startswith('.') else name
to_validate = name.lstrip('.')
if to_validate:
self._DOT_VALIDATOR.validate(to_validate)
except ValidationError as v:
Expand Down
15 changes: 11 additions & 4 deletions src/zope/configuration/tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def resolve(self, name):
self.assertIs(found, _target)
self.assertEqual(context._resolved, 'tried')

def test_fromUnicode_w_resolve_dot(self):
def test_fromUnicode_w_resolve_dots(self):
_target = object()
class Context(object):
_resolved = None
Expand All @@ -105,9 +105,16 @@ def resolve(self, name):
go = self._makeOne()
context = Context()
bound = go.bind(context)
found = bound.fromUnicode('.')
self.assertIs(found, _target)
self.assertEqual(context._resolved, '.')
for name in (
'.',
'..',
'.foo',
'..foo.bar'
):
__traceback_info__ = name
found = bound.fromUnicode(name)
self.assertIs(found, _target)
self.assertEqual(context._resolved, name)

def test_fromUnicode_w_resolve_but_validation_fails(self):
from zope.schema import Text
Expand Down

0 comments on commit 4083b7b

Please sign in to comment.