[Templates] Bug Alert! [% something.foo() %] => [% something %]

Andy Wardley abw@cre.canon.co.uk
Wed, 16 Aug 2000 10:27:49 +0100


I found a rather obscure, but potentially troublesome bug last night
while investigating Jonas' problem with this:

  [% cgi.param() %]

It's the empty () that causes the problem.  It turns out that a small
bug in the parser code generator happened to tickle a small bug in the
stash with the outcome that the above is treated as:

  [% cgi %]

The empty () causes the last node to be ignored altogether.

The workaround is to remove the empty parens and it then works
as expected:

  [% cgi.param %]

Here are the two changes that fix the bug.   I'll be rolling out another
beta in the next day or so.

A


lib/Template/Directive.pm   ~line 210

     push(@$args, '{ ' . join(', ', @$hash) . ' }')
 	if @$hash;

-    return '' unless @$args;
+    return '0' unless @$args;
     return '[ ' . join(', ', @$args) . ' ]';
 }


lib/Template/Stash.pm	~line 195

 	# if $ident is a list reference, then we evaluate each item in the
 	# identifier against the previous result, using the root stash
 	# ($self) as the first implicit 'result'...

-	foreach (my $i = 0; $i < $size; $i += 2) {
+	foreach (my $i = 0; $i <= $size; $i += 2) {
 	    $result = $self->_dotop($root, @$ident[$i, $i+1]);
 	    last unless defined $result;
 	    $root = $result;
 	}

-- 
Andy Wardley <abw@kfs.org>   Signature regenerating.  Please remain seated.
     <abw@cre.canon.co.uk>   For a good time: http://www.kfs.org/~abw/