Skip to content

Commit 5b98d06

Browse files
vvillait88claude
andcommitted
fix(discovery): _table_cell escapes backslashes before pipes
Mirrors node-commerce CodeQL fix. Prior implementation escaped \`|\` but not \`\\\`, so an input like \`a\\|b\` rendered as literal-backslash + cell-terminator — breaking the markdown table row. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 70847bc commit 5b98d06

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

agentscore_commerce/discovery/skill_md.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,12 @@ def _quote_yaml(value: str) -> str:
214214

215215

216216
def _table_cell(value: str) -> str:
217-
"""Sanitize a string for a markdown table cell — pipes break the row."""
218-
return value.replace("|", "\\|")
217+
r"""Sanitize a string for a markdown table cell.
218+
219+
Escape backslashes first (so existing ``\\`` aren't treated as escapes), then escape
220+
pipes (which would otherwise terminate the cell).
221+
"""
222+
return value.replace("\\", "\\\\").replace("|", "\\|")
219223

220224

221225
def _frontmatter(input: BuildSkillMdInput) -> str:

tests/test_skill_md.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ def test_escapes_pipes_in_files(self) -> None:
210210
out = build_skill_md(cfg)
211211
assert "| a\\|b | `https://x.example/foo\\|bar` |" in out
212212

213+
def test_escapes_backslashes_before_pipes(self) -> None:
214+
"""Backslashes must escape first, otherwise existing `\\` consumes the pipe escape."""
215+
cfg = _base()
216+
cfg.files = [SkillMdLink(label="a\\|b", url="https://x.example/c\\d")]
217+
out = build_skill_md(cfg)
218+
# Backslash → `\\`, then pipe → `\|`. Combined for `a\|b`: `a\\\|b`.
219+
assert "| a\\\\\\|b | `https://x.example/c\\\\d` |" in out
220+
213221

214222
class TestPaymentSection:
215223
def test_renders_one_row_per_rail(self) -> None:

0 commit comments

Comments
 (0)