]> sipb.mit.edu Git - ikiwiki.git/commitdiff
improve escaping of wikilinks and preprocessor directives
authorJoey Hess <joey@kodama.kitenet.net>
Tue, 18 Nov 2008 07:43:17 +0000 (02:43 -0500)
committerJoey Hess <joey@kodama.kitenet.net>
Tue, 18 Nov 2008 07:43:17 +0000 (02:43 -0500)
The old method failed for '[' x 3.

IkiWiki/Plugin/aggregate.pm
IkiWiki/Plugin/recentchanges.pm
IkiWiki/Plugin/recentchangesdiff.pm
debian/changelog

index f256b3ac1a9a58a10324ee6e1eb3523cecf4da7c..6cdbbc0e91e4bccac8e8c55a2078ad4200978611 100644 (file)
@@ -610,7 +610,7 @@ sub add_page (@) { #{{{
        my $template=template($feed->{template}, blind_cache => 1);
        $template->param(title => $params{title})
                if defined $params{title} && length($params{title});
-       $template->param(content => htmlescape(htmlabs($params{content},
+       $template->param(content => wikiescape(htmlabs($params{content},
                defined $params{base} ? $params{base} : $feed->{feedurl})));
        $template->param(name => $feed->{name});
        $template->param(url => $feed->{url});
@@ -637,11 +637,9 @@ sub add_page (@) { #{{{
        }
 } #}}}
 
-sub htmlescape ($) { #{{{
+sub wikiescape ($) { #{{{
        # escape accidental wikilinks and preprocessor stuff
-       my $html=shift;
-       $html=~s/(?<!\\)\[\[/\\\[\[/g;
-       return $html;
+       return encode_entities(shift, '\[\]');
 } #}}}
 
 sub urlabs ($$) { #{{{
index 3f70664ac36990c87113721cac1daf2af42706fc..39a123ccf978ad9931b04e6f24cee1301c5ed992 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 use strict;
 use IkiWiki 2.00;
 use Encode;
+use HTML::Entities;
 
 sub import { #{{{
        hook(type => "getsetup", id => "recentchanges", call => \&getsetup);
@@ -163,7 +164,7 @@ sub store ($$$) { #{{{
        if (ref $change->{message}) {
                foreach my $field (@{$change->{message}}) {
                        if (exists $field->{line}) {
-                               $field->{line} =~ s/(?<!\\)\[\[/\\\[\[/g;
+                               $field->{line} = encode_entities($field->{line}, '\[\]');
                        }
                }
        }
index 36acef72ebccf8978c3c4e8348074ef4bca0565c..bc793bada98ab9867ebf59fd8f2a153c61741d71 100644 (file)
@@ -4,6 +4,7 @@ package IkiWiki::Plugin::recentchangesdiff;
 use warnings;
 use strict;
 use IkiWiki 2.00;
+use HTML::Entities;
 
 my $maxlines=200;
 
@@ -39,7 +40,7 @@ sub pagetemplate (@) { #{{{
                                $diff=join("", @lines);
                        }
                        # escape links and preprocessor stuff
-                       $diff =~ s/(?<!\\)\[\[/\\\[\[/g;
+                       $diff = encode_entities($diff, '\[\]');
                        $template->param(diff => $diff);
                }
        }
index 294cae6dc7b4c4f94c41d66140ba5df6c2c7152b..eeb9fe6ce7570d810c83906a714e69d38fbb99a7 100644 (file)
@@ -3,6 +3,8 @@ ikiwiki (2.71) UNRELEASED; urgency=low
   * htmlbalance: New plugin contributed by Simon McVittie.
   * Change deb dependencies to list Text::Markdown before markdown (really
     this time).
+  * Improve escaping of wikilinks and preprocessor directives in content
+    produced by aggregate and recentchanges.
 
  -- Joey Hess <joeyh@debian.org>  Mon, 17 Nov 2008 14:02:10 -0500