You are here: Foswiki>Tasks Web>Item10807 (17 Dec 2011, GeorgeClark)Edit Attach

Item10807: Prevent recursion in template expansion

pencil
Priority: Urgent
Current State: Closed
Released In: 1.1.4
Target Release: patch
Applies To: Engine
Component:
Branches: Release01x01 trunk
Reported By: ArthurClemens
Waiting For:
Last Change By: GeorgeClark
-- ArthurClemens - 28 May 2011

Re-opening as a release blocker, as this has caused a problem.

The expansion limit is set to 999; however it is never reset, so if any template is instantiated 1000 times (without recursion) you will get an exception.

For example, add %ICON{"alert"}% to a topic 1001 times. It will bomb.

Patch (trunk) follows:
Index: Templates.pm
===================================================================
--- Templates.pm   (revision 13382)
+++ Templates.pm   (working copy)
@@ -192,6 +192,8 @@
         $val =~ s/%TMPL:P{(.*?)}%/$this->expandTemplate($1)/ge;
     }
 
+    $this->{expansionRecursions}->{$template} -= 1;
+
     return $val;
 }

-- CrawfordCurrie - 14 Dec 2011

That is certainly an improvement. Tested on release branch.

Test template:

%TMPL:INCLUDE{"view"}%
%TMPL:P{"loop"}%

%TMPL:DEF{"loop"}%
loop
%TMPL:P{"loop"}%
%TMPL:END%

-- ArthurClemens - 14 Dec 2011

Added a small improvement to the testcase; the 'x' operator allows you to repeat a string many times.

-- CrawfordCurrie - 15 Dec 2011

 
Topic revision: r16 - 17 Dec 2011, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy