X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/4e1806ef7c002a4a333c5822c13d7ceca303bf70..80b244d857584c7cc4092e00265b62568c2a681e:/IkiWiki/CGI.pm?ds=sidebyside diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 5baa6c179..cb83319e6 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -110,11 +110,23 @@ sub decode_cgi_utf8 ($) { } } +sub safe_decode_utf8 ($) { + my $octets = shift; + # call decode_utf8 on >= 5.20 only if it's not already decoded, + # otherwise it balks, on < 5.20, always call it + if ($] < 5.02 || !Encode::is_utf8($octets)) { + return decode_utf8($octets); + } + else { + return $octets; + } +} + sub decode_form_utf8 ($) { if ($] >= 5.01) { my $form = shift; foreach my $f ($form->field) { - my @value=map { decode_utf8($_) } $form->field($f); + my @value=map { safe_decode_utf8($_) } $form->field($f); $form->field(name => $f, value => \@value, force => 1, @@ -351,7 +363,8 @@ sub cgi_getsession ($) { { FileName => "$config{wikistatedir}/sessions.db" }) }; if (! $session || $@) { - error($@." ".CGI::Session->errstr()); + my $error = $@; + error($error." ".CGI::Session->errstr()); } umask($oldmask);