summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordieter <dieter@handshake.de>2020-03-27 18:44:16 +0100
committerdieter <dieter@handshake.de>2020-03-27 18:44:16 +0100
commit9ba79faab112c085dac560572f39d36df8422992 (patch)
treedb068a7f984fd64a2fc98efd0d54539e0b18fda2
parent3405e36e68ec8963d38d1282b578829e35ffed94 (diff)
downloadzope-tales-9ba79faab112c085dac560572f39d36df8422992.tar.gz
Cleanups for Plone 5.2
-rw-r--r--CHANGES.rst6
-rw-r--r--src/zope/tales/expressions.py10
-rw-r--r--src/zope/tales/tests/test_expressions.py14
3 files changed, 27 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index e0c4214..b25d895 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,7 +5,11 @@
5.0.2 (unreleased)
==================
-- Nothing changed yet.
+- Cleanups for Plone 5.2:
+ * in path alternatives, whitespace can now surround ``|``,
+ * non-ASCII in ``SubPathExpr`` now raises a ``CompilerError``
+ (instead of a ``UnicodeEncodeError``; to be compatible with
+ the ``chameleon`` template engine).
5.0.1 (2019-06-26)
diff --git a/src/zope/tales/expressions.py b/src/zope/tales/expressions.py
index 81a626b..13c7097 100644
--- a/src/zope/tales/expressions.py
+++ b/src/zope/tales/expressions.py
@@ -67,7 +67,13 @@ class SubPathExpr(object):
# Parse path
compiledpath = []
currentpath = []
- for element in str(path).strip().split('/'):
+ try:
+ path = str(path)
+ except Exception as e:
+ raise engine.getCompilerError()(
+ 'could not convert %r to `str`: %s: %s'
+ % (path, e.__class__.__name__, str(e)))
+ for element in path.strip().split('/'):
if not element:
raise engine.getCompilerError()(
'Path element may not be empty in %r' % path)
@@ -242,7 +248,7 @@ class PathExpr(object):
_interp = re.compile(
- r'\$(%(n)s)|\${(%(n)s(?:/[^}|]*)*(?:\|%(n)s(?:/[^}|]*)*)*)}'
+ r'\$(%(n)s)|\${(%(n)s(?:/[^}|]*)*(?:\|\s*%(n)s(?:/[^}|]*)*)*)}'
% {'n': NAME_RE})
diff --git a/src/zope/tales/tests/test_expressions.py b/src/zope/tales/tests/test_expressions.py
index 1996445..c6b94b3 100644
--- a/src/zope/tales/tests/test_expressions.py
+++ b/src/zope/tales/tests/test_expressions.py
@@ -161,6 +161,20 @@ class TestParsedExpressions(ExpressionTestBase):
expr = self.engine.compile('path:ErrorGenerator/%s|b|c/d/e' % e)
self._check_evals_to(expr, 'boot')
+ def testOrPathWithSpaces(self):
+ expr = self.engine.compile('path:a | b | c/d/e')
+ self._check_evals_to(expr, 'boot')
+
+ for e in 'Undefined', 'AttributeError', 'LookupError', 'TypeError':
+ expr = self.engine.compile(
+ 'path:ErrorGenerator/%s | b | c/d/e' % e)
+ self._check_evals_to(expr, 'boot')
+
+ def testNonAsciiPath(self):
+ error = self.engine.getCompilerError()
+ with self.assertRaises(error):
+ expr = self.engine.compile(u'path: รค')
+
def test_path_CONTEXTS(self):
self.context.contexts = 42
self._check_evals_to('CONTEXTS', 42)