The long-time definition of TWiki variables specifies \" and \' as escapes for " and ' respectively in parameter values. This allows you to write:
%FORMFIELD{"Priority" format="\" double \' single"}%
to get
" double ' single
Unfortunately \ is no similarly escaped, so there is
no way to include the strings \" and \' in the parameters to a TWiki variable. Try it.
The immediate fix to this is to handle \\ as an escape for \, which would allow you to write
\\\"
to get
\"
This is a two-character fix in Attrs.pm, though the
AttrsTests unit testcase should also be updated.
I consider this as Urgent because that string is needed to escape a quote in an enclosing TWiki variable - for example,
%SEARCH{"%FORMFIELD{"AFormField" format="\\\"$value\\\""}%"}%
This is a gotcha that has already bitten many people, including me.
At the same time it might be sensible to support escapes for other elements of TWiki syntax, such as \% and \}. This would make it
significantly easier to use TWiki Variables, especially when used with Peter's new %ENCODE{type="quote"}% However this is a more extensive change, as it impacts the twiki variable parser as well.
Perhaps over time we will also be able to replace, or at least provide an alternative to, the
$quot
and
$percnt
style of escapes that alienate so many people.
CC
I agree that this needs to be resolved. However, I do not think that this should be blocking the 4.1.0 release, hence changing this to "enhancement" state. This enhancement would be risky to introduce showtly before the release.
--
PTh
After tripping over this several times while working on the query lookup, I am raising it again to Normal. It needs to be fixed.
CC
Outch. This broke all of my twiki apps. I now happen to need three backslashes to get one. I only needed two to get one before. Reopening, marked as urgent.
The problem appears on a string like
\\"
which was translated to
\"
before in Attrs.pm. Two blackslashes
\\
are now escaped and
\"
not, thus the attribute values are truncated wrongly.
That's because the code uses a translation token at the wrong
place producing an interim string like
^@92"
now (^@92 encodes
\\
). Before the interim string was
\^@32
which encodes
\"
.
So the sequence
\\"
is ambiguous to be translated either to
^@92"
or
\^@32
and this precedence changed
unfortunately.
Wrt the above example, did you ever try
%SEARCH{"%FORMFIELD{"AFormField" format="\\"$value\\""}%"}%
An isolated backslash followed by something else but a
"
or a
'
had no meaning for the Attrs parser before.
MD
OK, given that Michael is having problems I imagine that means other people will as well. So I will revert the testcase as well.
This report is rejected.
CC