#1686
fix(viewer): preserve code whitespace in PDF reports
Problem
PDF reports collapse whitespace in PoC scripts, raw evidence and fenced code blocks. A valid indented Python PoC becomes invalid when copied from the PDF, and repeated spaces inside payload strings are changed.
Fixes #1683.
Change
Route the two code-rendering paths through a shared paragraph helper that normalizes text, expands tabs to eight-column stops, escapes markup and preserves spaces and line breaks. Retaining ReportLab Paragraph preserves the current long-line wrapping, styling and pagination. Prose keeps its existing formatting.
Validation
- Eight new regression cases: seven failed before the fix, while the long-token wrapping control passed.
pytest tests/test_report_pdf.py tests/test_fenced_code.py tests/test_viewer.py -q: 84 passed with Python 3.12.14 and frozen dependencies. The initial sandbox run blocked 18 viewer socket-binding tests; all passed when local sockets were permitted.- Tests cover raw/fenced PoC, raw evidence, fenced narrative code, tabs and blank lines, literal markup, 3,000-character/space lines within the frame, and a 250-line code block across pages.
- Full-repository Ruff format/check and Bandit passed.
- Independent review found no blocking issue; all eight new tests also passed independently.
Validation used synthetic reports and local viewer requests. Live scan and report relay remain unverified.
[Medium impact] The PR appears safe to merge; no actionable issues were found.
Summary
Code blocks in PDF reports now share
_code_paragraph, which expands tabs, escapes markup, and preserves spaces and line breaks.Reviews (1) · Last reviewed commit: "fix(viewer): preserve code whitespace in..." · Reviewed by Greptile