Skip to content

fix(report): escape Markdown table cells - #140

Merged
ssf0409 merged 2 commits into
ssf0409:mainfrom
devtechedge:fix/134-markdown-table-escaping
Sep 15, 2026
Merged

ssf0409 merged 2 commits into
ssf0409:mainfrom
devtechedge:fix/134-markdown-table-escaping

Conversation

@devtechedge

Copy link
Copy Markdown
Contributor

Summary

  • add a private _md_cell() helper for Markdown table cells
  • escape pipes, collapse newlines, and neutralize a leading <
  • apply escaping to per-task and baseline-gate Markdown tables
  • add regression coverage for hostile task IDs and table column counts
  • document the fix under [Unreleased]

Validation

The added tests cover task IDs containing |, raw HTML, and newlines, including both the per-task and baseline-gate tables.

make verify should validate the full repository before merge.

Closes #134

Task ids or gate values containing `|`, line breaks, or a leading `<`
broke the per-task and baseline-gate Markdown tables piped into the job
summary: an embedded pipe changed the parsed column count and a cell
opening with raw HTML could be interpreted as an HTML element. Escape
every interpolated Markdown cell with a private `_md_cell` helper and
add regression tests for both tables.
@devtechedge
devtechedge force-pushed the fix/134-markdown-table-escaping branch from defeac4 to 0412997 Compare September 14, 2026 01:44
@ssf0409
ssf0409 self-requested a review September 14, 2026 03:29

@ssf0409 ssf0409 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contribution, added one feedback!

Comment thread src/tracelens/reporting/generator.py Outdated
"""
text = text.replace("\r\n", "\n").replace("\r", "\n").replace("\n", " ")
text = text.replace("|", "\\|")
if text.startswith("<"):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of doing this check, can we use built in html.escape() to escape the html elements?

example

from html import escape

escape("task <img src=x> & result", quote=False)
# 'task &lt;img src=x&gt; &amp; result'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, html.escape() is cleaner than the hand-rolled < check.

_md_cell now collapses newlines and escapes | first, then returns escape(text, quote=False).

Pipe escaping and newline collapsing stay because html.escape handles neither, and they are Markdown concerns rather than HTML ones.

This also widens the fix slightly: every &, < and > in a cell is escaped now, not just a leading <.

Tests and the changelog entry are updated to match, with an & case added.

Table cells now neutralise &, < and > through html.escape instead of
only backslash-escaping a leading <, so a task id or gate value can
neither open a raw HTML element nor inject an entity into the Markdown
tables piped into $GITHUB_STEP_SUMMARY. Pipe escaping and newline
collapsing stay because they are Markdown, not HTML, concerns.

@ssf0409 ssf0409 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@ssf0409
ssf0409 merged commit 7effc40 into ssf0409:main Sep 15, 2026
15 of 16 checks passed
ssf0409 pushed a commit that referenced this pull request Sep 15, 2026
Resolves the overlap with #140 (Markdown table cell escaping): the gate
table keeps main's `_md_cell` escaping and this branch's Evidence column, the
#134 test expects the eight-column row, and both changelog entries sit under
[Unreleased].

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N1GtYXaFXi7LpXcpRxBP7o
devtechedge added a commit to devtechedge/oss-contributions that referenced this pull request Sep 15, 2026
@devtechedge

Copy link
Copy Markdown
Contributor Author

Thanks for merging, @ssf0409.

Switching to html.escape() was the better call, since it covers & and > as well as the leading < I had special-cased.

Keeping the pipe and newline handling separate turned out to matter too, because those are Markdown problems rather than HTML ones.

Appreciate you taking the time to review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(report): Markdown table cells are not escaped, so a | or raw HTML in a task id breaks the per-task and gate tables piped into the job summary

2 participants