[ZPT] Semantics of double slash in path expressions changed from Zope2.5.1 to 2.6?
Dieter Maurer
dieter@handshake.de
Sat, 7 Dec 2002 00:28:56 +0100
Clemens Robbenhaar writes:
> ....
> After reading the diff of the sources I found there is an explanation
> for this change as a fix for http://collector.zope.org/Zope/581
>
> The issue has been that one cannot do things like 'd/?k' in 2.5.1,
> when "k" evaluates to the empty string. As 'd' may be something with
> item access, this may make indeed sense, as the empty string is not a
> valid id, but a valid key for an item.
>
> E.g.:
>
> <tal:block
> define="
> d python:{'1':'Yabba', '0':'Yabba', '':'Hey!'};
> k string:"
> replace="d/?k">test</tal:block>
>
> renders "Hey!" with 2.6.0, but creates an error with 2.5.1
>
> Now as some 'd.maurer' has collected this issue, who is most probably
> Dieter Maurer,
Indeed.
> I guess there are real use cases for this issue. ;)
Sure.
A real life example caused the exception that led me
to file the bug report.
> But are there uses cases for empty string access without the '/?'
> notation?
Sure. The same as with the "?variable" syntax:
Path expressions are supposed to access dictionaries (with strings
as keys). Suppose, one of its keys it the empty string.
How will you access it via a path expression?
It would not be senseful to treat
tal:define="XXX string:something;
... .../?XXX/...;
"
different from
tal:define="... .../something/...;"
> ....
> A possible workaround would be to treat double slashes as a single one
> when splitting a path expression. This would leave the solution for
> the collector issue #581 intact but avoid the less intuitive behaviour
> for multiple consecutive slashes.
It would no address the "empty key" issue for dictionaries.
Dieter