1 # Copyright (C) 2017-2020 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 is(PublicInbox::Hval::to_filename('foo bar '), 'foo-bar',
51 'to_filename has no trailing -');
53 is(PublicInbox::Hval::to_filename("foo bar\nanother line\n"), 'foo-bar',
54 'to_filename has no repeated -, and nothing past LF');
56 is(PublicInbox::Hval::to_filename("foo....bar"), 'foo.bar',
57 'to_filename squeezes -');
59 is(PublicInbox::Hval::to_filename(''), undef, 'empty string returns undef');
62 PublicInbox::Hval::src_escape($s);
63 is($s, "\\0\\a\n", 'src_escape works as intended');
65 foreach my $s ('Hello/World.pm', 'Zcat', 'hello world.c', 'Eléanor', '$at') {
66 my $attr = to_attr($s);
67 is(from_attr($attr), $s, "$s => $attr => $s round trips");
71 my $bad = to_attr('foo//bar');
72 ok(!$bad, 'double-slash rejected');