Error: now disappears $xx and \$xx
Brought to you by:
nhruby,
richardarcher
Hi, I was looking for a correction to the disappearing $,
then I tried this version of templates.inc
But I found two errors:
- templates.inc->set_var still eats "$xx", where x is a
literal
- templates.inc->set_var eats the \ in "\$xx"
if you do the following:
$t->set_var(array( "t1" => " $es ", "t2" => "
\$123 " ));
the variables inside the template object will became:
t1="" and t2="$123".
t1 is clearly wrong.
t2 seems wrong too (I don't know the inner
representation). After doing a $t->parse and a $t->p, in
place of {t2} you will get a "$123" which is wrong.
Logged In: YES
user_id=278685
t1 depends completely on your setting of the PHP variable
$es - you should be testing against ' $es ' so that PHP is not
doing variable substitution within the string.
Logged In: YES
user_id=279311
I am confident that the current CVS version of template.inc
behaves correctly in both these situations. Your second test
result containing a "$" suggests to me that you're
running an old version of template.inc. That kludge was
removed from the script in April.
The last change I made to resolve this issue was to run all
variable values through preg_replace prior to substitution.
While this incurs a performance hit over the previous
kludges, it's practically guaranteed to result in the
correct behaviour.
I have attached my test script and template for this
problem. The output consists of all template.inc's debugging
output followed by a table of three columns. The first
column is a description of the test, the second is the
intended result as plain text and the third is the result
after running through template.
...R.
special char test for template.inc
Logged In: YES
user_id=206472
I second layne weathers on this.
Also add ${noTDTags} to your testspecialchars.tpl where
there is no space, no td tags, nothing, between the $ sign
and the curly brace.
Logged In: YES
user_id=279311
I tested this, and it works fine for me.
Test files attached...
updated test for special chars
Logged In: NO
you must use \\\$123
Logged In: YES
user_id=279311
Please post some code as an attachment which demonstrates
this problem. So SF doesn't escape the sequence which causes
the problem. Also, please include your copy of template.inc
in the attachment.
I still believe you're running a non-current version of
template.inc. The logic in the current version seems to me
to be unflawed.
...R.
Logged In: YES
user_id=279311
I'm closing this bug. I can't see any way the current logic
in template.inc can be fooled into breaking in this way.
I'm happy to look at any further reports of strange
behaviour. Preferably accompanied by a test script and
template which demonstrates the incorrect behaviour. Please
attach a file to the bug report containing:
a PHP script
a template file
your version of template.inc
sample output
a mock up of *correct* output
Thank you!
...R.