X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/2c784773879b228b7dfec2c6d092c9e1e98ab97b..0a56f05b53c8b9a91478c2af932a60c4a46c441b:/IkiWiki/Plugin/meta.pm diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 134c0ce5d..4aa545a93 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -13,7 +13,6 @@ my %author; my %authorurl; my %license; my %copyright; -my %redirected; sub import { #{{{ hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1); @@ -25,6 +24,7 @@ sub filter (@) { #{{{ my %params=@_; $meta{$params{page}}=''; + delete $pagestate{$params{page}}{meta}{redir}; return $params{content}; } # }}} @@ -71,20 +71,29 @@ sub preprocess (@) { #{{{ } } elsif ($key eq 'redir') { - $redirected{$page}=1; + return "" if $destpage ne $page; my $safe=0; - if ($value =~ /^$config{wiki_link_regexp}$/) { + if ($value !~ /^\w+:\/\//) { + add_depends($page, $value); my $link=bestlink($page, $value); if (! length $link) { return "[[meta ".gettext("redir page not found")."]]"; } - if ($redirected{$link}) { - # TODO this is a cheap way of avoiding - # redir cycles, but it is really too strict. - return "[[meta ".gettext("redir to page that itself redirs is not allowed")."]]"; - } - $value=urlto($link, $destpage); + + $value=urlto($link, $page); $safe=1; + + # redir cycle detection + $pagestate{$page}{meta}{redir}=$link; + 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}; + } } else { $value=encode_entities($value);