MD5: Removed base64 mode. Changed to trigger on startend.
parent
198bb55834
commit
5e2c0ee6b4
|
@ -17,7 +17,7 @@ description 'Calculate the MD5 digest of a string.';
|
|||
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/MD5.pm';
|
||||
category 'transformations';
|
||||
|
||||
triggers start => 'md5', 'md5sum';
|
||||
triggers startend => 'md5', 'md5sum';
|
||||
|
||||
my $css = share('style.css')->slurp;
|
||||
|
||||
|
@ -31,27 +31,15 @@ sub html_output {
|
|||
}
|
||||
|
||||
handle remainder => sub {
|
||||
# Exit unless a string is found after the mode (if any)
|
||||
if (/^(hex|base64|)\s*(.*)$/i) {
|
||||
my $command = $1 || '';
|
||||
my $str = $2 || '';
|
||||
return unless $str;
|
||||
|
||||
if ($command && $command eq 'base64') {
|
||||
# Calculate the md5 of the string and return it in base64 if that
|
||||
# is the selected mode.
|
||||
# The string is encoded to get the utf8 representation instead of
|
||||
# perls internal representation of strings, before it's passed to
|
||||
# the md5 subroutine.
|
||||
$str = md5_base64 (encode "utf8", $str);
|
||||
}
|
||||
else {
|
||||
# Defaults to hex encoding when no other mode was selected.
|
||||
$str = md5_hex (encode "utf8", $str);
|
||||
}
|
||||
if (/^\s*(.*)\s*$/) {
|
||||
# Exit unless a string is found
|
||||
return unless $1;
|
||||
# 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;
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
4
t/MD5.t
4
t/MD5.t
|
@ -13,8 +13,8 @@ ddg_goodie_test(
|
|||
DDG::Goodie::MD5
|
||||
)],
|
||||
'md5 digest this!' => test_zci('3838c8fb10a114e6d21203359ef147ad', html=>qr/.*/),
|
||||
'md5 hex gimme the hex digest' => test_zci('0ce78eeb15abe053207d79f9b8e5cbab', html=>qr/.*/),
|
||||
'md5sum base64 gimme the digest encoded in base64' => test_zci('INa7hD+ZcscImFVGHvnuvQ', html=>qr/.*/),
|
||||
'duckduckgo md5' => test_zci('96898bb8544fa56b03c08cdc09886c6c', html=>qr/.*/),
|
||||
'md5sum the sum of a string' => test_zci('a704c8833f9850cd342ead27207ca1a1', html=>qr/.*/),
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue