Refactor the charset guessing.
authorSteinar H. Gunderson <sesse@debian.org>
Tue, 2 Jan 2007 22:30:18 +0000 (23:30 +0100)
committerSteinar H. Gunderson <sesse@debian.org>
Tue, 2 Jan 2007 22:30:18 +0000 (23:30 +0100)
perl/Sesse/pr0n/Common.pm
perl/Sesse/pr0n/WebDAV.pm

index 2ca54cfa7dedcc19a2b65b15baf37c9689599c57..bc598545a4b97e66da5a478710fbb6ff671ade62 100644 (file)
@@ -554,6 +554,20 @@ sub add_new_event {
        return ();
 }
 
+sub guess_charset {
+       my $text = shift;
+       my $decoded;
+
+       eval {
+               $decoded = Encode::decode("utf-8", $text, Encode::FB_CROAK);
+       };
+       if ($@) {
+               $decoded = Encode::decode("iso8859-1", $text);
+       }
+
+       return $decoded;
+}
+
 1;
 
 
index 6d116d072012748ac79d172c4035c641bcc566ec..2cadbcd4aa60cf72d12be54f2aedf120438fa484 100644 (file)
@@ -544,13 +544,7 @@ EOF
                }
                
                # Ugh, Windows XP seems to be sending this in... something that's not UTF-8, at least
-               my $takenby_given;
-               eval {
-                       $takenby_given = Encode::decode("utf-8", $apr->param('takenby'), Encode::FB_CROAK);
-               };
-               if ($@) {
-                       $takenby_given = Encode::decode("iso8859-1", $apr->param('takenby'));
-               }
+               my $takenby_given = Sesse::pr0n::Common::guess_charset($apr->param('takenby'));
 
                if (defined($takenby_given) && $takenby_given !~ /^\s*$/ && $takenby_given !~ /[<>&]/ && length($takenby_given) <= 100) {
                        $takenby = $takenby_given;