From 5959a32f9746aa600fd852f6b11f635ad2020253 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 8 Dec 2007 19:39:32 -0500 Subject: real redir cycle detection --- IkiWiki/Plugin/meta.pm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'IkiWiki/Plugin/meta.pm') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 968e6ccee..4aa545a93 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -71,6 +71,7 @@ sub preprocess (@) { #{{{ } } elsif ($key eq 'redir') { + return "" if $destpage ne $page; my $safe=0; if ($value !~ /^\w+:\/\//) { add_depends($page, $value); @@ -78,13 +79,21 @@ sub preprocess (@) { #{{{ if (! length $link) { return "[[meta ".gettext("redir page not found")."]]"; } + + $value=urlto($link, $page); + $safe=1; + + # redir cycle detection $pagestate{$page}{meta}{redir}=$link; - if ($pagestate{$link}{meta}{redir}) { - # TODO: real cycle detection - return "[[meta ".gettext("redir not allowed to point to a page that contains a redir")."]]"; + my $at=$page; + my %seen; + while (exists $pagestate{$at}{meta}{redir}) { + if ($seen{$at}) { + return "[[meta ".gettext("redir cycle is not allowed")."]]"; + } + $seen{$at}=1; + $at=$pagestate{$at}{meta}{redir}; } - $value=urlto($link, $destpage); - $safe=1; } else { $value=encode_entities($value); -- cgit v1.2.3