Commit 12f9f634 authored by Evan Simpson's avatar Evan Simpson

Fix Collector #538. Path expressions with a non-path final alternate no

longer try to call a value returned by that alternate.
parent 431601ab
......@@ -6,6 +6,9 @@ Zope Changes
Bugs Fixed
- Collector #538: Hybrid path expressions no longer attempt to call
a value returned by the final, non-path alternate.
- Collector #573: ZTUtils Iterator didn't catch AttributeError.
- Deprecated hasRole alias in User.py failed to return result.
......
......@@ -17,7 +17,7 @@ Page Template-specific implementation of TALES, with handlers
for Python expressions, string literals, and paths.
"""
__version__='$Revision: 1.42 $'[11:-2]
__version__='$Revision: 1.43 $'[11:-2]
import re, sys
from TALES import Engine, CompilerError, _valid_name, NAME_RE, \
......@@ -154,6 +154,7 @@ class PathExpr:
def __init__(self, name, expr, engine):
self._s = expr
self._name = name
self._hybrid = 0
paths = expr.split('|')
self._subexprs = []
add = self._subexprs.append
......@@ -163,6 +164,7 @@ class PathExpr:
# This part is the start of another expression type,
# so glue it back together and compile it.
add(engine.compile(('|'.join(paths[i:]).lstrip())))
self._hybrid = 1
break
add(SubPathExpr(path)._eval)
......@@ -187,8 +189,11 @@ class PathExpr:
else:
break
else:
# On the last subexpression allow exceptions through.
# On the last subexpression allow exceptions through, and
# don't autocall if the expression was not a subpath.
ob = self._subexprs[-1](econtext)
if self._hybrid:
return ob
if self._name == 'nocall' or isinstance(ob, StringType):
return ob
......
......@@ -43,6 +43,15 @@ class ExpressionTests(unittest.TestCase):
assert ec.evaluate('d/ | nothing') == 'blank'
assert ec.evaluate('d/?blank') == 'blank'
def testHybrid(self):
'''Test hybrid path expressions'''
ec = self.ec
assert ec.evaluate('x | python:1+1') == 2
assert ec.evaluate('x | python:int') == int
assert ec.evaluate('x | string:x') == 'x'
assert ec.evaluate('x | string:$one') == '1'
assert ec.evaluate('x | not:exists:x')
def test_suite():
return unittest.makeSuite(ExpressionTests)
......
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