ReviewOS

home-lang/home

fix(markdown): sanitize source-controlled ANSI output

#747
Closed glennmichael123 opened this 10 days ago ·
10 days ago

Parent

Confirmed parity gap

Home ANSI rendering writes document-controlled bytes directly through paragraph text, decoded entities, link hrefs, image src/title, code-fence language badges, and image URL collection. Bun live Rust routes all of those surfaces through sanitize_source_text, removing C0/DEL/C1 controls and complete CSI/OSC sequences before they can reach terminal output. Home only strips escapes from one image-alt path, so OSC 52 clipboard writes, OSC title changes, CSI queries, BEL terminators, and related controls can survive through the other sinks.

The copied Bun corpus already carries exact regressions in js/bun/md/md-edge-cases.test.ts for source text and link/metadata controls.

Scope

  • Port Bun sanitize_source_text as a shared Zig helper with an allocation-free fast path.
  • Apply it to text, decoded entities, href construction, image metadata, code badges, and collected image URLs.
  • Preserve renderer-owned lifetimes and propagate or record allocation failure through the existing paths.
  • Verify ordinary text and URLs remain byte-for-byte unchanged and hostile C0/C1/CSI/OSC input is removed.

This is the direct Bun implementation, not an assertion or test workaround.

10 days ago

Implemented and pushed to origin/main in 394fbca (fix(markdown): sanitize terminal source text (#747)). The direct Bun sanitizer is now applied to renderer text, post-decoded entities, link href construction, image src/title ownership, code-fence language badges, and collected image URLs. Printable input retains the allocation-free fast path; C0 except newline/tab, DEL, UTF-8 C1 controls, and complete CSI/OSC sequences are removed. Verification: focused leaf suite 5/5 pass at 171 MB peak, covering sanitizer fast/hostile paths plus real text, href, image metadata, and collector sinks; zig ast-check, zig fmt --check, and git diff --check pass. Author and committer are glennmichael123 gtorregosa@gmail.com, no coauthors.

Sign in to comment on this issue.