From 820755463d88fcc2f66974c829ad71f9228f7c75 Mon Sep 17 00:00:00 2001 From: Martin Donath Date: Tue, 12 May 2026 09:51:22 +0200 Subject: [PATCH] fix: don't consider `[]` and `[][]` link references (#663) Signed-off-by: squidfunk --- python/tests/unit/collectors/test_references.py | 16 ++++++++++------ python/zensical/collectors/references/cursor.py | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/python/tests/unit/collectors/test_references.py b/python/tests/unit/collectors/test_references.py index 841fae1..9ea5c83 100644 --- a/python/tests/unit/collectors/test_references.py +++ b/python/tests/unit/collectors/test_references.py @@ -310,12 +310,6 @@ class TestLinkReferences: b"id", id="link-ref-with-empty-text", ), - pytest.param( - b"[][]", - b"", - b"", - id="link-ref-with-empty-text-and-id", - ), pytest.param( b"[text \\]][id]", b"text \\]", @@ -472,6 +466,16 @@ class TestLinkReferences: refs = collect(md) assert len(refs) == 0 + def test_no_link_ref_empty_shortcut(self) -> None: + md = b"[]" + refs = collect(md) + assert len(refs) == 0 + + def test_no_link_ref_empty_brackets(self) -> None: + md = b"[][]" + refs = collect(md) + assert len(refs) == 0 + # --------------------------------------------------------------------------- diff --git a/python/zensical/collectors/references/cursor.py b/python/zensical/collectors/references/cursor.py index 92eeb88..b79f2cc 100644 --- a/python/zensical/collectors/references/cursor.py +++ b/python/zensical/collectors/references/cursor.py @@ -424,6 +424,10 @@ def _scan_link_or_link_ref(cursor: Cursor) -> Link | LinkReference | None: # Consume link id id, end = _scan_link_id(cursor, end) + # Ignore empty shortcut references like `[]` or `[][]`. + if id is None and text.start == text.end: + return None + # Advance cursor and return link reference cursor.advance(end - start) return LinkReference(