diff options
author | Colin Watson <cjwatson@ubuntu.com> | 2022-08-08 13:35:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-08 13:35:51 +0100 |
commit | b541ca989f041e7b1b05aec9d6d4c29917b9e7a0 (patch) | |
tree | ae6248ad179d6c19767091b824c4b089948ea98d | |
parent | 4d490966549c43e56a6a5aaf17955922ad15ad18 (diff) | |
parent | 859456919f9df4acb5e902e2b88cc4e612a3024c (diff) | |
download | zope-tales-b541ca989f041e7b1b05aec9d6d4c29917b9e7a0.tar.gz |
Merge pull request #27 from cjwatson/fix-invalid-variable-name-message
Fix "Invalid variable name" error for base of path
-rw-r--r-- | CHANGES.rst | 3 | ||||
-rw-r--r-- | src/zope/tales/expressions.py | 2 | ||||
-rw-r--r-- | src/zope/tales/tests/test_expressions.py | 7 |
3 files changed, 10 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 9bd9497..e7ec251 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,6 +7,9 @@ - Add support for Python 3.9, 3.10. +- Fix error message raised if the first element of a path expression is not + a valid name. + 5.1 (2020-07-06) ================ diff --git a/src/zope/tales/expressions.py b/src/zope/tales/expressions.py index dd8980c..18db2b1 100644 --- a/src/zope/tales/expressions.py +++ b/src/zope/tales/expressions.py @@ -124,7 +124,7 @@ class SubPathExpr(object): base = first[0] if base and not _valid_name(base): raise engine.getCompilerError()( - 'Invalid variable name "%s"' % element) + 'Invalid variable name "%s"' % base) self._base = base compiledpath[0] = first[1:] self._compiled_path = tuple(compiledpath) diff --git a/src/zope/tales/tests/test_expressions.py b/src/zope/tales/tests/test_expressions.py index 1653c29..9d62875 100644 --- a/src/zope/tales/tests/test_expressions.py +++ b/src/zope/tales/tests/test_expressions.py @@ -193,8 +193,13 @@ class TestParsedExpressions(ExpressionTestBase): def test_dynamic_invalid_variable_name(self): from zope.tales.tales import CompilerError - with self.assertRaisesRegex(CompilerError, "Invalid variable name"): + with self.assertRaisesRegex( + CompilerError, 'Invalid variable name "123"'): self.engine.compile('path:a/?123') + # Deliberate typo for the TAL construct "structure ...". + with self.assertRaisesRegex( + CompilerError, 'Invalid variable name "structured a"'): + self.engine.compile('structured a/b') def testOldStyleClassIsCalled(self): class AnOldStyleClass: |