From 60e40f6f3601137036f398365ba6b4f2464ae9cf Mon Sep 17 00:00:00 2001 From: Tarik Moussa Date: Sun, 14 Jun 2026 03:47:27 +0200 Subject: [PATCH] fix(wiki): exclude URL-shaped bibkeys from claim parsing _parse_claims now skips matches where bibkey contains spaces or starts with "http", preventing Markdown hyperlinks like [text](https://...) from being misidentified as citations. Add two tests. Co-Authored-By: Claude Sonnet 4.6 --- codex/wiki.py | 4 ++++ tests/wiki/test_compile.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/codex/wiki.py b/codex/wiki.py index 65f988b..8a386e5 100644 --- a/codex/wiki.py +++ b/codex/wiki.py @@ -228,6 +228,10 @@ def _parse_claims(markdown: str) -> list[Claim]: text = match.group("text").strip() bibkey = match.group("bibkey").strip() locator = (match.group("locator") or "").strip() + # Skip URL-shaped bibkeys ([text](https://...)) and multi-word bibkeys + # (real BibKeys never contain spaces or start with "http") + if " " in bibkey or bibkey.startswith("http"): + continue if text and bibkey: claims.append(Claim(text=text, bibkey=bibkey, locator=locator)) return claims diff --git a/tests/wiki/test_compile.py b/tests/wiki/test_compile.py index e2f5ad5..89498be 100644 --- a/tests/wiki/test_compile.py +++ b/tests/wiki/test_compile.py @@ -121,6 +121,20 @@ def test_parse_claims_multiple() -> None: assert len(claims) == 2 +def test_parse_claims_ignores_markdown_links() -> None: + """Markdown hyperlinks like [text](https://example.com) are NOT parsed as claims.""" + md = "See the [related work](https://example.com) for details." + claims = _parse_claims(md) + assert claims == [] + + +def test_parse_claims_ignores_multi_word_bibkey() -> None: + """Multi-word 'bibkeys' (spaces inside) are not treated as real citations.""" + md = "Some text [not a bibkey here] and more." + claims = _parse_claims(md) + assert claims == [] + + # --------------------------------------------------------------------------- # _run_grounding_guard # ---------------------------------------------------------------------------