|
1 | 1 | """Tests for lib.pdf.wg21.""" |
2 | 2 |
|
3 | 3 | from lib.pdf.types import Block, Line, Span |
4 | | -from lib.pdf.wg21 import extract_metadata_from_blocks |
| 4 | +from lib.pdf.wg21 import extract_metadata_from_blocks, REPLY_TO_CONTINUATION_CAP |
5 | 5 |
|
6 | 6 |
|
7 | 7 | def _meta_block(lines_text, page_num=0, font_size=9.0): |
@@ -95,3 +95,24 @@ def test_reply_to_name_then_email_on_next_line(): |
95 | 95 | meta, consumed = extract_metadata_from_blocks([b]) |
96 | 96 | assert "reply-to" in meta |
97 | 97 | assert any("Bob Jones" in a for a in meta["reply-to"]) |
| 98 | + |
| 99 | + |
| 100 | +def test_reply_to_continuation_capped(): |
| 101 | + """Reply-to loop must stop after REPLY_TO_CONTINUATION_CAP blocks, |
| 102 | + even if later blocks still contain emails.""" |
| 103 | + reply_block = _meta_block(["Reply-to: Alice <alice@x.com>"]) |
| 104 | + # Generate more continuation blocks than the cap allows |
| 105 | + extra_count = REPLY_TO_CONTINUATION_CAP + 5 |
| 106 | + extras = [ |
| 107 | + _meta_block([f"Person{n} <p{n}@x.com>"]) |
| 108 | + for n in range(extra_count) |
| 109 | + ] |
| 110 | + blocks = [reply_block] + extras |
| 111 | + meta, consumed = extract_metadata_from_blocks(blocks) |
| 112 | + # The continuation blocks consumed must not exceed the cap |
| 113 | + # (block 0 is consumed as the reply-to label block itself) |
| 114 | + continuation_consumed = consumed - {0} |
| 115 | + assert len(continuation_consumed) == REPLY_TO_CONTINUATION_CAP |
| 116 | + # The block just past the cap must not be consumed |
| 117 | + past_cap_idx = 1 + REPLY_TO_CONTINUATION_CAP |
| 118 | + assert past_cap_idx not in consumed |
0 commit comments