TALES string expressions cannot co-exist with dynamic path expressions
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 2 |
Invalid
|
Low
|
Unassigned |
Bug Description
In Zope 2.10.6, a string TALES expression's results cannot then be used in a dynamic path expression. This seems to be a result of using the unicode-friendly 'zope.tales' from Zope 3 with the ancient 'unrestrictedTr
Steps to reproduce:
In an empty folder, add two subfolders, 'gallery', and 'submission-
<ul tal:define=
<li tal:define="gallery container/
<strong tal:content=
</li>
<li tal:define=
<strong tal:content=
</li>
</ul>
The first define simulates a function call (without the call) in my code which returns a classic 'str' object. The first dynamic path expression, 'container/
Module OFS.Traversable, line 284, in unrestrictedTra
- __traceback_info__: ([u'y', u'r', u'e', u'l', u'l', u'a', u'g', u'-', u'n', u'o', u'i', u's', u's', u'i', u'm', u'b', u'u'], u's')
KeyError: u's'
Which comes from what happens in OFS.Traversable's unrestrictedTra
if isinstance(path, str):
# Unicode paths are not allowed
path = path.split('/')
else:
path = list(path)
It turns out that tal:define=
In Products.
I don't know if unrestrictedTra
It appears that the Zope 2.11.0 code has the same issue.
This is not a critical issue for me - I know there are numerous ways around it (ie - changing ``string:
Bug 142117 opened this issue up years ago, and was rejected with 'if a str is expected then thats what it should be'. That may have been OK in 2002-2003, but not in 2008 when Zope 3 and semi-modern Python-isms are being used.
I agree with your conclusion.
The problem stems from Zope 2 using 8bit strings for object ids. So PageTemplates should use the
while it's certainly possible to use non-ASCII characters in path
names, they'll always be stored in some encoding. I imagine the
default encoding would be latin-1 and there would probably be a way to
change it (frankly I don't know how, but I think Plone somehow manages
to use UTF8 I think). Anyway, certainly the publisher must be using
this implicit encoding when mapping unicode URLs to object paths, so
there must be some way of figuring this out. Whatever it is, I think
the TALES traversal machinery in Products.
same logic.
Since I'm the one who ported Zope 2 to use the Zope 3 ZPT PageTemplates.
implementation, I feel responsible for making this legacy use case
work again. However, it would help me a lot (and probably speed things
up) if you could perhaps create some tests for this use case. There
should be some tests that you can extend in Products.
Submitting a patch that just adds failing tests would be very helpful
already.
Thanks!