1 # Copyright (C) 2017-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use_ok 'PublicInbox::Hval', qw(to_attr);
8 # reverse the result of to_attr
12 if ($str =~ s/\AZ([a-f0-9]{2})//ms) {
13 $first = chr(hex($1));
15 $str =~ s!::([a-f0-9]{2})!chr(hex($1))!egms;
22 -no_obfuscate_re => qr/(?:example\.com)\z/i,
24 'meta@public-inbox.org' => 1,
37 PublicInbox::Hval::obfuscate_addrs($ibx, $html);
40 hello@example•comm
43 test@public-inbox•org
45 te.st@example•org
48 is($html, $exp, 'only obfuscated relevant addresses');
50 $exp = 'https://example.net/foo@example.net';
51 PublicInbox::Hval::obfuscate_addrs($ibx, my $res = $exp);
52 is($res, $exp, 'does not obfuscate URL with Message-ID');
54 is(PublicInbox::Hval::to_filename('foo bar '), 'foo-bar',
55 'to_filename has no trailing -');
57 is(PublicInbox::Hval::to_filename("foo bar\nanother line\n"), 'foo-bar',
58 'to_filename has no repeated -, and nothing past LF');
60 is(PublicInbox::Hval::to_filename("foo....bar"), 'foo.bar',
61 'to_filename squeezes -');
63 is(PublicInbox::Hval::to_filename(''), undef, 'empty string returns undef');
66 PublicInbox::Hval::src_escape($s);
67 is($s, "\\0\\a\n", 'src_escape works as intended');
69 foreach my $s ('Hello/World.pm', 'Zcat', 'hello world.c', 'Eléanor', '$at') {
70 my $attr = to_attr($s);
71 is(from_attr($attr), $s, "$s => $attr => $s round trips");
75 my $bad = to_attr('foo//bar');
76 ok(!$bad, 'double-slash rejected');