From deb4371b9ea4f79ae89c48333485aed6e307e291 Mon Sep 17 00:00:00 2001 From: elhoim Date: Mon, 31 Aug 2026 00:01:58 +0000 Subject: [PATCH] Fix backslash-unaware pipe escaping in markdown tables response_to_table() escaped '|' as '\\|' without first escaping existing backslashes. A value already containing a literal backslash immediately before a pipe (a Windows path, a regex snippet) turned '\|' into '\\|' after escaping: markdown reads that as an escaped backslash followed by an UNescaped pipe delimiter, breaking the table row it was meant to protect. Fix: escape backslashes before escaping pipes, so any pre-existing backslash is doubled first and the pipe delimiter stays properly escaped. --- bin/cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/cli.py b/bin/cli.py index 92267b1..054124e 100644 --- a/bin/cli.py +++ b/bin/cli.py @@ -406,8 +406,8 @@ def response_to_table(response: Any) -> List[str]: return ["| Key | Value |", "| --- | --- |", "| _(empty)_ | |"] lines = ["| Key | Value |", "| --- | --- |"] for key in sorted(response.keys()): - safe_key = str(key).replace("\n", " ").replace("|", "\\|") - safe_value = to_inline(response[key]).replace("\n", " ").replace("|", "\\|") + safe_key = str(key).replace("\n", " ").replace("\\", "\\\\").replace("|", "\\|") + safe_value = to_inline(response[key]).replace("\n", " ").replace("\\", "\\\\").replace("|", "\\|") lines.append(f"| `{safe_key}` | {safe_value} |") return lines if isinstance(response, list): @@ -415,10 +415,10 @@ def response_to_table(response: Any) -> List[str]: return ["| Index | Value |", "| --- | --- |", "| 0 | _(empty)_ |"] lines = ["| Index | Value |", "| --- | --- |"] for idx, item in enumerate(response): - safe_value = to_inline(item).replace("\n", " ").replace("|", "\\|") + safe_value = to_inline(item).replace("\n", " ").replace("\\", "\\\\").replace("|", "\\|") lines.append(f"| `{idx}` | {safe_value} |") return lines - safe_value = str(response).replace("\n", " ").replace("|", "\\|") + safe_value = str(response).replace("\n", " ").replace("\\", "\\\\").replace("|", "\\|") return ["| Value |", "| --- |", f"| `{safe_value}` |"] generated_at = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%SZ")