* Consolidated all decode_utf8 in FormBuilder's fields to make the code more
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Tue, 11 Jul 2006 21:20:14 +0000 (21:20 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Tue, 11 Jul 2006 21:20:14 +0000 (21:20 +0000)
  readable and avoid future mistakes. The patch seems to work and for the
  first time I have a UTF-8 username ;-) (Faidon)
* Use form->field consistently, not form->param.

IkiWiki/CGI.pm
debian/changelog
doc/patchqueue/decode-from.mdwn

index 53e151dc2696eb193dbabf9c61bb9986dcaa6f6a..857f9b9a38bbfe6ace53f149149e7b5328ea24e6 100644 (file)
@@ -41,6 +41,17 @@ sub page_locked ($$;$) { #{{{
        return 0;
 } #}}}
 
        return 0;
 } #}}}
 
+sub decode_form_utf8 ($) { #{{{
+       my $form = shift;
+       foreach my $f ($form->field) {
+               next if Encode::is_utf8(scalar $form->field($f));
+               $form->field(name  => $f,
+                            value => decode_utf8($form->field($f)),
+                            force => 1,
+                           );
+       }
+} #}}}
+
 sub cgi_recentchanges ($) { #{{{
        my $q=shift;
        
 sub cgi_recentchanges ($) { #{{{
        my $q=shift;
        
@@ -106,6 +117,8 @@ sub cgi_signin ($$) { #{{{
        }
        
        if ($form->submitted) {
        }
        
        if ($form->submitted) {
+               decode_form_utf8($form);
+
                # Set required fields based on how form was submitted.
                my %required=(
                        "Login" => [qw(name password)],
                # Set required fields based on how form was submitted.
                my %required=(
                        "Login" => [qw(name password)],
@@ -166,6 +179,8 @@ sub cgi_signin ($$) { #{{{
        }
 
        if ($form->submitted && $form->validate) {
        }
 
        if ($form->submitted && $form->validate) {
+               decode_form_utf8($form);
+               
                if ($form->submitted eq 'Login') {
                        $session->param("name", $form->field("name"));
                        if (defined $form->field("do") && 
                if ($form->submitted eq 'Login') {
                        $session->param("name", $form->field("name"));
                        if (defined $form->field("do") && 
@@ -282,6 +297,8 @@ sub cgi_prefs ($$) { #{{{
                        value => userinfo_get($user_name, "locked_pages"));
        }
        
                        value => userinfo_get($user_name, "locked_pages"));
        }
        
+       decode_form_utf8($form);
+       
        if ($form->submitted eq 'Logout') {
                $session->delete();
                redirect($q, $config{url});
        if ($form->submitted eq 'Logout') {
                $session->delete();
                redirect($q, $config{url});
@@ -326,9 +343,11 @@ sub cgi_editpage ($$) { #{{{
        );
        my @buttons=("Save Page", "Preview", "Cancel");
        
        );
        my @buttons=("Save Page", "Preview", "Cancel");
        
-       # This untaint is safe because titlepage removes any problimatic
+       decode_form_utf8($form);
+       
+       # This untaint is safe because titlepage removes any problematic
        # characters.
        # characters.
-       my ($page)=decode_utf8($form->param('page'));
+       my ($page)=$form->field('page');
        $page=titlepage(possibly_foolish_untaint(lc($page)));
        if (! defined $page || ! length $page ||
            $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
        $page=titlepage(possibly_foolish_untaint(lc($page)));
        if (! defined $page || ! length $page ||
            $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
@@ -373,10 +392,8 @@ sub cgi_editpage ($$) { #{{{
        }
        elsif ($form->submitted eq "Preview") {
                require IkiWiki::Render;
        }
        elsif ($form->submitted eq "Preview") {
                require IkiWiki::Render;
-               # Apparently FormBuilder doesn't not treat input as
-               # utf-8, so decode from it.
-               my $content=decode_utf8($form->field('editcontent'));
-               my $comments=decode_utf8($form->field('comments'));
+               my $content=$form->field('editcontent');
+               my $comments=$form->field('comments');
                $form->field(name => "editcontent",
                                value => $content, force => 1);
                $form->field(name => "comments",
                $form->field(name => "editcontent",
                                value => $content, force => 1);
                $form->field(name => "comments",
@@ -395,9 +412,9 @@ sub cgi_editpage ($$) { #{{{
                if ($form->field("do") eq "create") {
                        my @page_locs;
                        my $best_loc;
                if ($form->field("do") eq "create") {
                        my @page_locs;
                        my $best_loc;
-                       my ($from)=$form->param('from')=~/$config{wiki_file_regexp}/;
+                       my ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
                        if (! defined $from || ! length $from ||
                        if (! defined $from || ! length $from ||
-                           $from ne $form->param('from') ||
+                           $from ne $form->field('from') ||
                            $from=~/$config{wiki_file_prune_regexp}/ ||
                            $from=~/^\// ||
                            $form->submitted eq "Preview") {
                            $from=~/$config{wiki_file_prune_regexp}/ ||
                            $from=~/^\// ||
                            $form->submitted eq "Preview") {
@@ -407,7 +424,7 @@ sub cgi_editpage ($$) { #{{{
                                my $dir=$from."/";
                                $dir=~s![^/]+/+$!!;
                                
                                my $dir=$from."/";
                                $dir=~s![^/]+/+$!!;
                                
-                               if ((defined $form->param('subpage') && length $form->param('subpage')) ||
+                               if ((defined $form->field('subpage') && length $form->field('subpage')) ||
                                    $page eq 'discussion') {
                                        $best_loc="$from/$page";
                                }
                                    $page eq 'discussion') {
                                        $best_loc="$from/$page";
                                }
@@ -463,8 +480,7 @@ sub cgi_editpage ($$) { #{{{
                # save page
                page_locked($page, $session);
                
                # save page
                page_locked($page, $session);
                
-               # Decode utf-8 since FormBuilder does not
-               my $content=decode_utf8($form->field('editcontent'));
+               my $content=$form->field('editcontent');
 
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;
 
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;
@@ -480,7 +496,7 @@ sub cgi_editpage ($$) { #{{{
                }
                if (defined $form->field('comments') &&
                    length $form->field('comments')) {
                }
                if (defined $form->field('comments') &&
                    length $form->field('comments')) {
-                       $message.=": ".decode_utf8($form->field('comments'));
+                       $message.=": ".$form->field('comments');
                }
                
                if ($config{rcs}) {
                }
                
                if ($config{rcs}) {
@@ -499,7 +515,7 @@ sub cgi_editpage ($$) { #{{{
                                        force => 1);
                                $form->tmpl_param("page_conflict", 1);
                                $form->field("editcontent", value => $conflict, force => 1);
                                        force => 1);
                                $form->tmpl_param("page_conflict", 1);
                                $form->field("editcontent", value => $conflict, force => 1);
-                               $form->field(name => "comments", value => decode_utf8($form->field('comments')), force => 1);
+                               $form->field(name => "comments", value => $form->field('comments'), force => 1);
                                $form->field("do", "edit)");
                                $form->tmpl_param("page_select", 0);
                                $form->field(name => "page", type => 'hidden');
                                $form->field("do", "edit)");
                                $form->tmpl_param("page_select", 0);
                                $form->field(name => "page", type => 'hidden');
index 8dd0996efcb7d270155e73c9636f24ab2d06ce51..391569fad0f666301b56945ebc7ac3284206b191 100644 (file)
@@ -14,8 +14,12 @@ ikiwiki (1.9) UNRELEASED; urgency=low
     area, and also way slow.
   * Match 'web commit from' in SVN and git, these are web commits too.
     (Faidon)
     area, and also way slow.
   * Match 'web commit from' in SVN and git, these are web commits too.
     (Faidon)
+  * Consolidated all decode_utf8 in FormBuilder's fields to make the code more
+    readable and avoid future mistakes. The patch seems to work and for the
+    first time I have a UTF-8 username ;-) (Faidon)
+  * Use form->field consistently, not form->param.
 
 
- -- Joey Hess <joeyh@debian.org>  Tue, 11 Jul 2006 16:54:00 -0400
+ -- Joey Hess <joeyh@debian.org>  Tue, 11 Jul 2006 17:18:39 -0400
 
 ikiwiki (1.8) unstable; urgency=low
 
 
 ikiwiki (1.8) unstable; urgency=low
 
index 4d385f67abe0a2e28ded068cf348df15584e0db1..9f1dd8df26330f49774ad0b67ec2402d06273a51 100644 (file)
@@ -1,3 +1,5 @@
+Wow, big hammer! [[patchqueue/Done]] though, with minor mods -- [[Joey]].
+
 From [[Faidon]]:
 
 I consolidated all decode_utf8 in FormBuilder's fields
 From [[Faidon]]:
 
 I consolidated all decode_utf8 in FormBuilder's fields