A link the autocomplete writes to a heading lands on an earlier heading that differs only in punctuation

This was reported in Headings with special characters have broken links and renaming, which is now in the Bug graveyard. The answer there was that [[Example#heading!]] was written by hand, because the autocomplete wrote [[Example#heading]]. That no longer holds. The autocomplete now keeps most punctuation in heading links, so it writes the very link that lands on the wrong heading.

Steps to reproduce

  1. Create a note Note.md:

    # a b
    
    # a.b
    
  2. In another note, type [[Note# and pick a.b from the list.

  3. Click the link.

Did you follow the troubleshooting guide?

Yes. Reproduced in a fresh vault with default settings.

Expected result

The link the autocomplete writes, [[Note#a.b]], leads to the heading a.b.

Actual result

It leads to a b. Every link to the second heading lands on the first, in both formats: [[Note#a.b]] and [x](Note.md#a.b). So the second heading cannot be linked at all.

The match folds case, runs of whitespace, a no-break space, and every ASCII punctuation character except ', - and _. I checked all 32 ASCII punctuation characters, plus case and spacing. Each of these pairs collides:

  • a b and a<c>b, for every punctuation character <c> except ', - and _. For a#b the autocomplete writes [[Note#a b]], which also goes to the first heading.
  • ab and AB
  • a b and a b (two spaces)
  • a b and a b with a no-break space

a'b, a-b and a_b are reached correctly.

The help promises links to headings, and it says the autocomplete is the way to make them. A link the autocomplete writes for a heading should reach that heading. One fix that keeps existing links working: prefer a heading whose text matches the link exactly, and fall back to the loose match only when none does.

Related feature request: Support special characters in headings for linking

Environment

Obsidian 1.14.5, installer 1.14.5, Windows 11. Also the same on 1.15.0 (Catalyst).

2 Likes