serokell / xrefcheck

Check cross-references in repository documents
Mozilla Public License 2.0
54 stars 3 forks source link

[BUG] Spaces in local links #279

Open dcastro opened 1 year ago

dcastro commented 1 year ago

Description

Say we have a file named a b.md.

The naive attempt to link to this file would be to use [link](a b.md), but the commonmark spec says that's not a valid link, see example 487. That will just be rendered as a plain text literal, not as a link.

The spec clarifies:

The destination can only contain spaces if it is enclosed in pointy brackets:

Which means there are two correct ways to refer to this file:

  1. By using pointy brackets: [link](<a b.md>)
  2. By percent-encoding the space: [link](a%20.md)

Xrefcheck says (1) is indeed valid, but it reports (2) as a broken link (which it isn't).

To Reproduce

Steps to reproduce the behavior:

$ touch 'a b.md'
$ echo "[link](a%20b.md)" > test.md
$ xrefcheck --include-untracked

Configuration file not found, using default config for GitHub repositories

=== Invalid references found ===                                                                                                                    

  ➥  In file test.md
     bad reference (relative) at src:1:1-16:
       - text: "link"
       - link: a%20b.md
       - anchor: -

     File does not exist:
       a%20b.md

Invalid references dumped, 1 in total.

Expected behavior

Expected the steps above to succeed without errors

Environment

Martoon-00 commented 1 year ago

:pogchamp: Interesting spot!