On Thu, Jun 28, 2001 at 06:34:58PM +0200, Jonas Liljegren wrote:
> I found that filters are cached and then reused if they are not called
> with any args.

[...]

> A patch to fix this bug is provided here, against Context.pm,v 2.19

There's just the small matter of these 12 failing tests... :-)


t/args..............ok                                                       
t/autoform..........ok 19/25Template process failed: undef error - poetry: filter not 
found
t/autoform..........ok 25/25FAILED tests 20-21                               
        Failed 2/25 tests, 92.00% okay
[...]
t/context...........ok 43/54Use of uninitialized value in regexp compilation at 
lib/Template/Filters.pm line 353.
t/context...........ok 54/54FAILED test 44                                   
        Failed 1/54 tests, 98.15% okay
[...]
t/filter............ok 27/124Template process failed: undef error - comment: filter 
not found
t/filter............ok 31/124Template process failed: undef error - test1: filter not 
found
t/filter............ok 39/124Template process failed: undef error - italic: filter not 
found
t/filter............ok 124/124FAILED tests 28-29, 32-33, 40-41, 53           
        Failed 7/124 tests, 94.35% okay
[...]
t/wrap..............ok 11/13Template process failed: undef error - bullet: filter not 
found
t/wrap..............NOK 13FAILED tests 12-13                                 
        Failed 2/13 tests, 84.62% okay
[...]
Failed Test  Status Wstat Total Fail  Failed  List of failed
-------------------------------------------------------------------------------
t/autoform.t                 25    2   8.00%  20-21
t/context.t                  54    1   1.85%  44
t/filter.t                  124    7   5.65%  28-29, 32-33, 40-41, 53
t/wrap.t                     13    2  15.38%  12-13
Failed 4/79 test scripts, 94.94% okay. 12/2159 subtests failed, 99.44% okay.
make: *** [test_dynamic] Error 29


How about this instead?  It only caches the filter when a specific
alias is given or if no arguments are provided in which case it
can safely cache it under it own name.

This only break one test which I've 'corrected' because it was 
abusing the problem you've indicated.  I think the new way is 
definately more correct.  It also tickled another minor bug which
I fixed.


Index: lib/Template/Context.pm
===================================================================
RCS file: /home/abw/lawnmower/cvsroot/Template2/lib/Template/Context.pm,v
retrieving revision 2.23
diff -u -r2.23 Context.pm
--- lib/Template/Context.pm     2001/06/27 14:24:06     2.23
+++ lib/Template/Context.pm     2001/06/29 11:55:46
@@ -206,7 +206,7 @@
 
     # alias defaults to name if undefined
     $alias = $name
-       unless defined($alias) or ref($name);
+       unless defined($alias) or ref($name) or $args;
 
     # cache FILTER if alias is valid
     $self->{ FILTER_CACHE }->{ $alias } = $filter
@@ -1419,8 +1419,8 @@
 
 =head1 VERSION
 
-2.22, distributed as part of the
-Template Toolkit version 2.03b, released on 25 June 2001.
+2.23, distributed as part of the
+Template Toolkit version 2.04, released on 27 June 2001.
 
 =head1 COPYRIGHT
 
Index: lib/Template/Filters.pm
===================================================================
RCS file: /home/abw/lawnmower/cvsroot/Template2/lib/Template/Filters.pm,v
retrieving revision 2.19
diff -u -r2.19 Filters.pm
--- lib/Template/Filters.pm     2001/06/27 14:24:06     2.19
+++ lib/Template/Filters.pm     2001/06/29 11:58:50
@@ -345,6 +345,7 @@
 
 sub replace_filter_factory {
     my ($context, $search, $replace) = @_;
+    $search = '' unless defined $search;
     $replace = '' unless defined $replace;
 
     return sub {
@@ -1207,8 +1208,8 @@
 
 =head1 VERSION
 
-2.18, distributed as part of the
-Template Toolkit version 2.03b, released on 25 June 2001.
+2.19, distributed as part of the
+Template Toolkit version 2.04, released on 27 June 2001.
 
 =head1 COPYRIGHT
 
Index: t/context.t
===================================================================
RCS file: /home/abw/lawnmower/cvsroot/Template2/t/context.t,v
retrieving revision 2.2
diff -u -r2.2 context.t
--- t/context.t 2000/11/01 12:01:44     2.2
+++ t/context.t 2001/06/29 12:00:18
@@ -1,3 +1,4 @@
+#!/usr/bin/perl -w                                         # -*- perl -*-
 #============================================================= -*-perl-*-
 #
 # t/context.t
@@ -155,16 +156,16 @@
 ok( ref $filter eq 'CODE' );
 ok( &$filter('<input/>') eq '&lt;input/&gt;' );
 
-$filter = $context->filter('replace', [ 'foo', 'bar' ]);
+$filter = $context->filter('replace', [ 'foo', 'bar' ], 'repsave');
 ok( $filter );
 ok( ref $filter eq 'CODE' );
 ok( &$filter('this is foo, so it is') eq 'this is bar, so it is' );
 
 # check filter got cached
-$filter = $context->filter('replace');
+$filter = $context->filter('repsave');
 ok( $filter );
 ok( ref $filter eq 'CODE' );
-ok( &$filter('this is foo, so it is') eq 'this is bar, so it is' );
+match( &$filter('this is foo, so it is'), 'this is bar, so it is' );
 
 
 #------------------------------------------------------------------------
Index: t/filter.t
===================================================================
RCS file: /home/abw/lawnmower/cvsroot/Template2/t/filter.t,v
retrieving revision 2.10
diff -u -r2.10 filter.t
--- t/filter.t  2001/06/23 08:41:59     2.10
+++ t/filter.t  2001/06/29 11:56:41
@@ -425,7 +425,9 @@
 [% global.blocktext FILTER truncate %]
 
 -- expect --
-The cat...
+The cat sat on the mat
+
+Mary ...
 
 -- test --
 [% "foo..." FILTER repeat(5) %]
@@ -826,4 +828,11 @@
 [% END %]>>
 -- expect --
 <<The cat sat on the mat>>
+
+-- test --
+[% FILTER format('++%s++') %]Hello World[% END %]
+[% FILTER format %]Hello World[% END %]
+-- expect --
+++Hello World++
+Hello World
 



A

-- 
Andy Wardley <[EMAIL PROTECTED]>   Signature regenerating.  Please remain seated.
     <[EMAIL PROTECTED]>   For a good time: http://www.kfs.org/~abw/


Reply via email to