Skip to content

Commit

Permalink
Merge pull request #27 from cjwatson/fix-invalid-variable-name-message
Browse files Browse the repository at this point in the history
Fix "Invalid variable name" error for base of path
  • Loading branch information
cjwatson committed Aug 8, 2022
2 parents 4d49096 + 8594569 commit b541ca9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -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)
================
Expand Down
2 changes: 1 addition & 1 deletion src/zope/tales/expressions.py
Expand Up @@ -124,7 +124,7 @@ def __init__(self, path, traverser, engine):
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)
Expand Down
7 changes: 6 additions & 1 deletion src/zope/tales/tests/test_expressions.py
Expand Up @@ -193,8 +193,13 @@ def testBadInitalDynamic(self):

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:
Expand Down

0 comments on commit b541ca9

Please sign in to comment.