]> Sergey Matveev's repositories - public-inbox.git/blob - t/hval.t
f93d6be6f0bd03df0fc04911348241b4a7fdc358
[public-inbox.git] / t / hval.t
1 # Copyright (C) 2017-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use_ok 'PublicInbox::Hval', qw(from_attr to_attr);
7
8 my $ibx = {
9         -no_obfuscate_re => qr/(?:example\.com)\z/i,
10         -no_obfuscate => {
11                 'meta@public-inbox.org' => 1,
12         }
13 };
14
15 my $html = <<'EOF';
16 hello@example.comm
17 hello@example.com
18 meta@public-inbox.org
19 test@public-inbox.org
20 test@a.b.c.org
21 te.st@example.org
22 EOF
23
24 PublicInbox::Hval::obfuscate_addrs($ibx, $html);
25
26 my $exp = <<'EOF';
27 hello@example&#8226;comm
28 hello@example.com
29 meta@public-inbox.org
30 test@public-inbox&#8226;org
31 test@a&#8226;b.c.org
32 te.st@example&#8226;org
33 EOF
34
35 is($html, $exp, 'only obfuscated relevant addresses');
36
37 is('foo-bar', PublicInbox::Hval::to_filename('foo bar  '),
38         'to_filename has no trailing -');
39
40 is('foo-bar', PublicInbox::Hval::to_filename("foo   bar\nanother line\n"),
41         'to_filename has no repeated -, and nothing past LF');
42
43 is('foo.bar', PublicInbox::Hval::to_filename("foo....bar"),
44         'to_filename squeezes -');
45
46 my $s = "\0\x07\n";
47 PublicInbox::Hval::src_escape($s);
48 is($s, "\\0\\a\n", 'src_escape works as intended');
49
50 foreach my $s ('Hello/World.pm', 'Zcat', 'hello world.c', 'ElĂ©anor', '$at') {
51         my $attr = to_attr($s);
52         is(from_attr($attr), $s, "$s => $attr => $s round trips");
53 }
54
55 {
56         my $bad = to_attr('foo//bar');
57         ok(!$bad, 'double-slash rejected');
58 }
59
60 done_testing();