Subject: | Should not look at utf8 flag |
The following test script fails (you may include this script into your distribution if you like):
#!perl
use strict;
use Test::More 'no_plan';
use String::UTF8::MD5;
my $latin1 = "\xff";
my $utf8 = "\xff"; utf8::upgrade($utf8);
is $latin1, $utf8;
is String::UTF8::MD5::md5($latin1), String::UTF8::MD5::md5($utf8);
__END__
$ perl5.22.0 /tmp/md5.pl
ok 1
not ok 2
# Failed test at /tmp/md5.pl line 10.
# got: '00594fd4f42ba43fc1ca0427a0576295'
# expected: 'f3f7437e8c1f303fc6742d9368b36cf6'
1..2
# Looks like you failed 1 test of 2.
For the same string the md5 fingerprint is different. It should be irrelevant whether the utf8 flag is set or not.
I propose to remove the Encode::is_utf8() check in your md5() function and do the encode_utf8() step always.