Repository navigation
fix(filesystem): escape plain text in generated PDFs - #5502
Merged
sauravpanda merged 5 commits intoAug 24, 2026
Merged
Conversation
Escaping first only worked because '#' and ' ' are not escapable, so the prefix length happened to survive html.escape and the [2:]/[3:]/[4:] offsets still landed correctly. Slice first, escape once at the point of use, and cover the three header branches in the regression test.
5 tasks
Contributor
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/ci/infrastructure/test_filesystem.py">
<violation number="1" location="tests/ci/infrastructure/test_filesystem.py:240">
P3: This blanket `'#' not in extracted_text` check rejects valid plain-text hashes even though the renderer only strips leading heading markers. Narrow the assertion to the actual `# ` / `## ` / `### ` prefixes.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
… absent `'#' not in extracted_text` claimed more than the renderer promises: only a leading `# `/`## `/`### ` marker is stripped, hashes anywhere else are plain text. Assert each header's source line is gone and its rendered text survives, and cover a literal `#1` in header content.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
A substring check passes with a leftover marker: 'Notes <i> #1' matches inside '# Notes <i> #1', so an H3 branch using the H1 offset would slip through. Compare against whole extracted lines instead, and cover the gaps that turned up alongside it: a non-header line starting with '#' (pins the 'startswith("# ")' boundary against an lstrip-style rewrite) and quote characters (html.escape emits '/", which ReportLab must unescape back). Rename to match what the test now covers.
… path Whole-line matching broke on any content long enough to wrap, so compare against a whitespace-collapsed blob instead and check leftover header markers separately against the rendered lines. Verified against headers and body lines that wrap over 2-3 lines. Add an append regression: append_file re-renders the whole document, so put the markup that trips ReportLab in the appended half to exercise that path on its own. Both PDF tests fail without the escape fix. Also condense the stale three-line comment above the render loop.
MagMueller
added a commit
that referenced
this pull request
Aug 27, 2026
`write_file` tells the model that PDF content is markdown, but after #5502 only `#` / `##` / `###` headings were styled. Bold, italic, inline code, and bullets printed as literal `**syntax**`. Keep the #5502 escape-first behavior (raw ReportLab markup cannot be restored — that is the parse bug). After `html.escape`, convert a small markdown subset to RML. Underscores stay literal so `snake_case` names are not italicized. `*` is only emphasis when it actually wraps a span — `2 * 3 * 4` and globs are left alone. Fenced blocks skip inline conversion so shell backticks survive. Heading offsets are shared with `DocxFile` via `_split_heading`. Fixes #5538 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Render markdown emphasis in PDF exports from `write_file` so PDFs match the documented markdown contract. Previously only `#`/`##`/`###` headings rendered; now bold, italic, inline code, and bullets format correctly while we keep the escape-first fix to avoid `ReportLab` parse issues. - Convert `**bold**`, `*italic*`, `` `inline` ``, and list bullets (`-`/`*`) to RML; code fences bypass inline conversion; underscores never italicize. - Keep glob tokens and arithmetic stars literal (e.g., `*.txt`, `**/foo/**`, `2 * 3 * 4`); inline code protects emphasis markers. - Restore inline code via collision-safe placeholders so user text cannot be mistaken for stash tokens. - Share heading parsing with `DocxFile` to align `#`/`##`/`###` levels; add tests for emphasis, bullets, fences, globs, and edge cases. <sup>Written for commit f168606. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/browser-use/browser-use/pull/5540?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
PdfFiledocuments its input as plain text, but each line was passed directly to ReportLab'sParagraphparser. Text such asComparison: 2 <b y & 5 > 4was interpreted as malformed markup, sowrite_filereturned an error instead of creating the PDF.What changed
FileSystem.write_filepath and verify the generated PDF text withPdfReaderBefore / after
</b>tagA screenshot is not applicable to this generated-file failure; the regression validates the resulting PDF content directly.
Testing
python -m pytest -o addopts='' -p no:cacheprovider --confcutdir=tests/ci/infrastructure -q tests/ci/infrastructure/test_filesystem.py(81 passed)./bin/lint.sh --staged(Ruff, Pyright, and other pre-commit hooks passed)Summary by cubic
Escape plain text and strip only leading Markdown header markers when generating PDFs so markup-like characters no longer break creation and extracted text matches input. Previously lines were passed to
reportlabParagraphas markup and could error; now we slice header markers to select styles and escape the remaining text.#,##,###to choose the style, then passhtml.escape(text)toParagraph; applies to bothFileSystem.write_fileandappend_file.FileSystem.write_file/append_file, validate withpypdfPdfReaderusing a whitespace-collapsed blob to tolerate wrapping; assert only leading header markers are stripped; cover literal#in content, a non-header starting with#, and quotes/angle brackets. No migration; heading styles unchanged.Written for commit e6b92be. Summary will update on new commits.