word edit: convert posted input to unicode
[sheet.git] / writer.plp
index cf19db4904e583610886c58e1e8257186954c4e2..d7167548f948991bf55aef311fd87ac7f86f7325 100644 (file)
@@ -153,12 +153,18 @@ if (exists $get{copy}) {
        $row = {%{$row}{ qw(prio lang cat) }};
 }
 elsif ($ENV{REQUEST_METHOD} eq 'POST') {{
+       sub parseinput {
+               return if not length $_[0];
+               require Encode;
+               return Encode::decode_utf8($_[0]);
+       }
+
        my $replace = $row;
-       $row = {%post{keys %wordcol}};
-       $row->{$_} = [grep {length} @{ $post{"\@$_"} }] for grep {
-               ref $wordcol{$_} eq 'HASH' and $wordcol{$_}->{-multiple}
-       } keys %wordcol;
-       $_ = length ? $_ : undef for values %{$row};
+       $row = {map { $_ =>
+               ref $wordcol{$_} eq 'HASH' && $wordcol{$_}->{-multiple} ?
+                       [ map { parseinput($_) } $post{'@'.$_}->@* ] :
+               scalar parseinput($post{$_})
+       } keys %wordcol};
 
        if (!$row->{form}) {
                if ($row->{ref} ne 'delete') {
@@ -190,8 +196,8 @@ elsif ($ENV{REQUEST_METHOD} eq 'POST') {{
                        $db->insert(word => {
                                ref   => $row->{id},
                                lang  => $lang,
-                               form  => $val,
-                       });
+                               form  => $_,
+                       }) for parseinput($val);
                        delete $fields{$field};
                }
                return 1;