From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C0100209C9 for ; Wed, 5 Oct 2016 23:57:28 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 16/17] t/thread-cycle: test self-referential messages Date: Wed, 5 Oct 2016 23:57:21 +0000 Message-Id: <20161005235722.14857-17-e@80x24.org> In-Reply-To: <20161005235722.14857-1-e@80x24.org> References: <20161005235722.14857-1-e@80x24.org> List-Id: Some broken (or malicious) mailers may include a generated Message-ID in its References header, so be prepared for it. --- t/thread-cycle.t | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/t/thread-cycle.t b/t/thread-cycle.t index 4d60f7e..0e1ecfe 100644 --- a/t/thread-cycle.t +++ b/t/thread-cycle.t @@ -51,18 +51,7 @@ my @msgs = map { } ); -my $th = PublicInbox::SearchThread->new(\@msgs); -$th->thread; -$th->order(sub { [ sort { $a->{id} cmp $b->{id} } @{$_[0]} ] }); -my $st = ''; -my @q = map { (0, $_) } @{$th->{rootset}}; -while (@q) { - my $level = shift @q; - my $node = shift @q or next; - $st .= (" "x$level). "$node->{id}\n"; - my $cl = $level + 1; - unshift @q, map { ($cl, $_) } @{$node->{children}} -} +my $st = thread_to_s(\@msgs); SKIP: { skip 'Mail::Thread missing', 1 unless $mt; @@ -71,7 +60,7 @@ SKIP: { $mt->order(sub { sort { $a->messageid cmp $b->messageid } @_ }); my $check = ''; - @q = map { (0, $_) } $mt->rootset; + my @q = map { (0, $_) } $mt->rootset; while (@q) { my $level = shift @q; my $node = shift @q or next; @@ -81,6 +70,28 @@ SKIP: { is($check, $st, 'Mail::Thread output matches'); } +@msgs = map { bless $_, 'PublicInbox::SearchMsg' } ( + { mid => 'a@b' }, + { mid => 'b@c', references => ' ' }, + { mid => 'd@e', references => '' }, +); + +is(thread_to_s(\@msgs), "a\@b\n b\@c\nd\@e\n", 'ok with self-references'); + done_testing(); -1; +sub thread_to_s { + my $th = PublicInbox::SearchThread->new(shift); + $th->thread; + $th->order(sub { [ sort { $a->{id} cmp $b->{id} } @{$_[0]} ] }); + my $st = ''; + my @q = map { (0, $_) } @{$th->{rootset}}; + while (@q) { + my $level = shift @q; + my $node = shift @q or next; + $st .= (" "x$level). "$node->{id}\n"; + my $cl = $level + 1; + unshift @q, map { ($cl, $_) } @{$node->{children}}; + } + $st; +} -- EW