Merge branch 'ready/anarcat/safe_unicode'

master
Simon McVittie 2014-09-12 21:23:29 +01:00
commit ab876a9947
1 changed files with 13 additions and 1 deletions

View File

@ -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,