]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Render.pm
switch to > n (currently 10) cycle loop protection since eg tumov's include
[ikiwiki.git] / IkiWiki / Render.pm
index cef770c6784025d89c2b1d64ffeca2391d5c3749..d7f07c08a1028f7a7353953610daeab7ac236e21 100644 (file)
@@ -84,11 +84,11 @@ sub parentlinks ($) { #{{{
        return @ret;
 } #}}}
 
-sub preprocess ($$$;$) { #{{{
+my %preprocessing;
+sub preprocess ($$$) { #{{{
        my $page=shift; # the page the data comes from
        my $destpage=shift; # the page the data will appear in (different for inline)
        my $content=shift;
-       my $onlystrip=shift || 0; # strip directives without processing
 
        my $handle=sub {
                my $escape=shift;
@@ -97,8 +97,10 @@ sub preprocess ($$$;$) { #{{{
                if (length $escape) {
                        return "[[$command $params]]";
                }
-               elsif ($onlystrip) {
-                       return "";
+               elsif ($preprocessing{$page}++ > 10) {
+                       # Avoid loops of preprocessed pages preprocessing
+                       # other pages that preprocess them, etc.
+                       return "[[$command preprocessing loop detected]]";
                }
                elsif (exists $hooks{preprocess}{$command}) {
                        # Note: preserve order of params, some plugins may
@@ -127,11 +129,13 @@ sub preprocess ($$$;$) { #{{{
                                        push @params, $val, '';
                                }
                        }
-                       return $hooks{preprocess}{$command}{call}->(
+                       my $ret=$hooks{preprocess}{$command}{call}->(
                                @params,
                                page => $page,
                                destpage => $destpage,
                        );
+                       $preprocessing{$page}--;
+                       return $ret;
                }
                else {
                        return "[[$command not processed]]";