Fix utf8 issues in calls to md5_hex.
authorJoey Hess <joey@kitenet.net>
Wed, 10 Mar 2010 00:55:19 +0000 (19:55 -0500)
committerJoey Hess <joey@kitenet.net>
Wed, 10 Mar 2010 00:55:19 +0000 (19:55 -0500)
This prevented comments containing some utf-8, including euro sign, from
being submitted. Since md5_hex is a C implementation, the string has to be
converted from perl's internal encoding to utf-8 when it is called. Some
utf-8 happened to work before, apparently by accident.

Note that this will change the checksums returned.

unique_comment_location is only used when posting comments, so the checksum
does not need to be stable there.

I only changed page_to_id for completeness; it is passed a comment page
name, and they can currently never contain utf-8.

In teximg, the bug could perhaps be triggered if the tex source contained
utf-8. If that happens, the checksum will change, and some extra work might
be performed on upgrade to rebuild the image.

IkiWiki/Plugin/comments.pm
IkiWiki/Plugin/teximg.pm
debian/changelog

index 8f8472f075f20c69e57578b75041c4ce145224f1..bbf850a17f24399a7e1fff86743f1c23d4c7503c 100644 (file)
@@ -839,7 +839,7 @@ sub unique_comment_location ($$$) {
 
        eval q{use Digest::MD5 'md5_hex'};
        error($@) if $@;
-       my $content_md5=md5_hex(shift);
+       my $content_md5=md5_hex(Encode::encode_utf8(shift));
 
        my $dir=shift;
 
@@ -862,7 +862,7 @@ sub page_to_id ($) {
        eval q{use Digest::MD5 'md5_hex'};
        error($@) if $@;
 
-       return "comment-".md5_hex($page);
+       return "comment-".md5_hex(Encode::encode_utf8(($page));
 }
        
 package IkiWiki::PageSpec;
index 0aaa796987d72613f58f0937db83bfe5934d757b..521af499fc77323870951883b49736509081cd8f 100644 (file)
@@ -8,6 +8,7 @@ use strict;
 use Digest::MD5 qw(md5_hex);
 use File::Temp qw(tempdir);
 use HTML::Entities;
+use Encode;
 use IkiWiki 3.00;
 
 my $default_prefix = <<EOPREFIX;
@@ -103,7 +104,7 @@ sub create ($$$) {
                $height = 12;
        }
 
-       my $digest = md5_hex($code, $height);
+       my $digest = md5_hex(Encode::encode_utf8($code), $height);
 
        my $imglink= $params->{page} . "/$digest.png";
        my $imglog =  $params->{page} .  "/$digest.log";
index c0f99291f367dfa749c7e8a8c61401830dc3958a..d1253c0796b35f12edb4a0290342cd0012965111 100644 (file)
@@ -1,3 +1,9 @@
+ikiwiki (3.20100303) UNRELEASED; urgency=low
+
+  * Fix utf8 issues in calls to md5_hex.
+
+ -- Joey Hess <joeyh@debian.org>  Tue, 09 Mar 2010 19:46:35 -0500
+
 ikiwiki (3.20100302) unstable; urgency=low
 
   * comments: Display number of comments in comment action link.