aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/CGI.pm
diff options
context:
space:
mode:
authorAntoine Beaupré <anarcat@koumbit.org>2014-09-09 23:11:51 -0400
committerAntoine Beaupré <anarcat@koumbit.org>2014-09-09 23:11:51 -0400
commitfeb21ebfacb341fc34244e1c9b8557fd81d1dfc1 (patch)
treee7d6713f00987a39f24bfd045d4f318e08678fa4 /IkiWiki/CGI.pm
parent6057107d71e9944bd6fd7093060e4297e617733e (diff)
downloadikiwiki-feb21ebfacb341fc34244e1c9b8557fd81d1dfc1.tar
ikiwiki-feb21ebfacb341fc34244e1c9b8557fd81d1dfc1.tar.gz
do not double-decode unicode in CGI forms
this works around a behavior change introduced in Encode.pm 2.53 shipped with the Perl 5.20 release described here: http://ikiwiki.info/bugs/garbled_non-ascii_characters_in_body_in_web_interface/
Diffstat (limited to 'IkiWiki/CGI.pm')
-rw-r--r--IkiWiki/CGI.pm14
1 files changed, 13 insertions, 1 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index c0d8f598b..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,