Merge pull request #550 from killerfish/md5fix

MD5 fix for issue #546
master
Jag Talon 2014-07-18 16:36:17 -04:00
commit 4830b4450a
2 changed files with 10 additions and 4 deletions

View File

@ -31,16 +31,18 @@ sub html_output {
}
handle remainder => sub {
s/^of (.*)$/$1/; # Remove 'of ' in queries like 'md5 of this'
s/^hash\s+(.*\S+)/$1/; # Remove 'hash' in queries like 'md5 hash this'
s/^of\s+(.*\S+)/$1/; # Remove 'of' in queries like 'md5 hash of this'
s/^"(.*)"$/$1/; # Remove quotes
if (/^\s*(.*)\s*$/) {
# Exit unless a string is found
return unless $1;
if (/^\s*(.*\S+)/) {
# The string is encoded to get the utf8 representation instead of
# perls internal representation of strings, before it's passed to
# the md5 subroutine.
my $str = md5_hex (encode "utf8", $1);
return $str, html => html_output ($str, $1);
} else {
# Exit unless a string is found
return;
}
};

View File

@ -18,6 +18,10 @@ ddg_goodie_test(
'md5 of password' => test_zci('5f4dcc3b5aa765d61d8327deb882cf99', html=>qr/.*/),
'md5sum of "this"' => test_zci('9e925e9341b490bfd3b4c4ca3b0c1ef2', html=>qr/.*/),
'md5 of "this' => test_zci('53d3e72f097a74f6d439fa88b91d5a71', html=>qr/.*/),
'md5 hash' => test_zci('0800fc577294c34e0b28ad2839435945', html=>qr/.*/),
'md5 hash ' => test_zci('0800fc577294c34e0b28ad2839435945', html=>qr/.*/),
'md5 hash of' => test_zci('8bf8854bebe108183caeb845c7676ae4', html=>qr/.*/),
'md5 hash of password ' => test_zci('5f4dcc3b5aa765d61d8327deb882cf99', html=>qr/.*/),
);
done_testing;