* Consolidated all decode_utf8 in FormBuilder's fields to make the code more
[ikiwiki.git] / doc / patchqueue / decode-from.mdwn
1 Wow, big hammer! [[patchqueue/Done]] though, with minor mods -- [[Joey]].
2
3 From [[Faidon]]:
4
5 I consolidated all decode_utf8 in FormBuilder's fields
6 to make the code more readable and avoid future mistakes. The patch
7 seems to work and for the first time I have a UTF-8 username ;-)
8 I think that with this patch and the previous one about locales, we're
9 done with UTF-8 support. Yay!
10
11         Index: IkiWiki/CGI.pm
12         ===================================================================
13         --- IkiWiki/CGI.pm      (revision 904)
14         +++ IkiWiki/CGI.pm      (working copy)
15         @@ -41,6 +41,17 @@
16                 return 0;
17          } #}}}
18          
19         +sub decode_form_utf8 ($) { #{{{
20         +       my $form = shift;
21         +       foreach my $f ($form->field) {
22         +               next if Encode::is_utf8(scalar $form->field($f));
23         +               $form->field(name  => $f,
24         +                            value => decode_utf8($form->field($f)),
25         +                            force => 1,
26         +                           );
27         +       }
28         +} #}}}
29         +
30          sub cgi_recentchanges ($) { #{{{
31                 my $q=shift;
32                 
33         @@ -166,6 +177,8 @@
34                 }
35          
36                 if ($form->submitted && $form->validate) {
37         +               decode_form_utf8($form);
38         +               
39                         if ($form->submitted eq 'Login') {
40                                 $session->param("name", $form->field("name"));
41                                 if (defined $form->field("do") && 
42         @@ -282,6 +295,8 @@
43                                 value => userinfo_get($user_name, "locked_pages"));
44                 }
45                 
46         +       decode_form_utf8($form);
47         +       
48                 if ($form->submitted eq 'Logout') {
49                         $session->delete();
50                         redirect($q, $config{url});
51         @@ -326,7 +341,7 @@
52                 );
53                 my @buttons=("Save Page", "Preview", "Cancel");
54                 
55         -       # This untaint is safe because titlepage removes any problimatic
56         +       # This untaint is safe because titlepage removes any problematic
57                 # characters.
58                 my ($page)=decode_utf8($form->param('page'));
59                 $page=titlepage(possibly_foolish_untaint(lc($page)));
60         @@ -367,16 +382,16 @@
61                                 force => 1);
62                 }
63                 
64         +       decode_form_utf8($form);
65         +       
66                 if ($form->submitted eq "Cancel") {
67                         redirect($q, "$config{url}/".htmlpage($page));
68                         return;
69                 }
70                 elsif ($form->submitted eq "Preview") {
71                         require IkiWiki::Render;
72         -               # Apparently FormBuilder doesn't not treat input as
73         -               # utf-8, so decode from it.
74         -               my $content=decode_utf8($form->field('editcontent'));
75         -               my $comments=decode_utf8($form->field('comments'));
76         +               my $content=$form->field('editcontent');
77         +               my $comments=$form->field('comments');
78                         $form->field(name => "editcontent",
79                                         value => $content, force => 1);
80                         $form->field(name => "comments",
81         @@ -463,8 +478,7 @@
82                         # save page
83                         page_locked($page, $session);
84                         
85         -               # Decode utf-8 since FormBuilder does not
86         -               my $content=decode_utf8($form->field('editcontent'));
87         +               my $content=$form->field('editcontent');
88          
89                         $content=~s/\r\n/\n/g;
90                         $content=~s/\r/\n/g;
91         @@ -480,7 +494,7 @@
92                         }
93                         if (defined $form->field('comments') &&
94                             length $form->field('comments')) {
95         -                       $message.=": ".decode_utf8($form->field('comments'));
96         +                       $message.=": ".$form->field('comments');
97                         }
98                         
99                         if ($config{rcs}) {
100         @@ -499,7 +513,7 @@
101                                                 force => 1);
102                                         $form->tmpl_param("page_conflict", 1);
103                                         $form->field("editcontent", value => $conflict, force => 1);
104         -                               $form->field(name => "comments", value => decode_utf8($form->field('comments')), force => 1);
105         +                               $form->field(name => "comments", value => $form->field('comments'), force => 1);
106                                         $form->field("do", "edit)");
107                                         $form->tmpl_param("page_select", 0);
108                                         $form->field(name => "page", type => 'hidden');