2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use PublicInbox::TestCommon;
8 require_mods qw(DBD::SQLite psgi);
9 use_ok 'PublicInbox::WWW';
11 F1V5OR6NMF.3M649JTLO9IXD@tux.localdomain/hehe1"'<foo
12 F1V5NB0PTU.3U0DCVGAJ750Z@tux.localdomain"'<>/foo
13 F1V5NB0PTU.3U0DCVGAJ750Z@tux&.ampersand
14 F1V5MIHGCU.2ABINKW6WBE8N@tux.localdomain/raw
15 F1V5LF9D9C.2QT5PGXZQ050E@tux.localdomain/t.atom
16 F1V58X3CMU.2DCCVAKQZGADV@tux.localdomain/../../../../foo
17 F1TVKINT3G.2S6I36MXMHYG6@tux.localdomain" onclick="alert(1)"
19 my @mids = split(/\n/, $msgs);
20 my $ibx = create_inbox 'bad-mids', version => 2, indexlevel => 'basic', sub {
24 $im->add(PublicInbox::Eml->new(<<"")) or BAIL_OUT;
29 Date: Fri, 02 Oct 1993 00:00:0$i +0000
36 my $config = cfg_new $tmpdir, <<EOM;
37 [publicinbox "bad-mids"]
38 address = $ibx->{-primary_address}
39 inboxdir = $ibx->{inboxdir}
41 my $www = PublicInbox::WWW->new($config);
42 test_psgi(sub { $www->call(@_) }, sub {
44 my $res = $cb->(GET('/bad-mids/'));
45 is($res->code, 200, 'got 200 OK listing');
46 my $raw = $res->content;
47 foreach my $mid (@mids) {
48 ok(index($raw, $mid) < 0, "escaped $mid");
51 my (@xmids) = ($raw =~ m!\bhref="([^"]+?)/T/#u"!sg);
52 is(scalar(@xmids), scalar(@mids),
53 'got escaped links to all messages');
55 @xmids = reverse @xmids;
56 my %uxs = ( gt => '>', lt => '<' );
57 foreach my $i (0..$#xmids) {
59 $uri =~ s/&#([0-9]+);/sprintf("%c", $1)/sge;
60 $uri =~ s/&(lt|gt);/$uxs{$1}/sge;
61 $res = $cb->(GET("/bad-mids/$uri/raw"));
62 is($res->code, 200, 'got 200 OK raw message '.$uri);
63 like($res->content, qr/Message-ID: <\Q$mids[$i]\E>/s,
64 'retrieved correct message');