#5578·marktext

[Bug] A reference definition like `[c++]: url` stops the document from opening

Author: ycyc0421Created Sep 28, 2026Updated Sep 28, 2026

Description

A document containing a reference definition whose label has a regex metacharacter, e.g. [c++]: https://example.com, fails to open.

updateRefLinkAndImage (packages/muya/src/block/scrollPage/index.ts) builds a RegExp from the definition label without escaping it. For c++ that is /\[c++\](?!:)/, which throws SyntaxError: Invalid regular expression: Nothing to repeat. The function runs while the definition is rendered during Muya#init, so the exception escapes init and the document does not load.

Other labels hit it too: a(b and x[y throw, and 1.0* / a.c do not throw but match the wrong references (a.c also re-renders [abc]). The same code also compares labels case-sensitively and without collapsing whitespace, while CommonMark matches [Foo Bar] to [foo bar]: url, so such references are not re-rendered when their definition changes.

Steps to Reproduce

  1. Create a file with:
    markdown
    [c++]: https://example.com
    
    see [c++]
  2. Open it in MarkText.

Expected Behavior

The document opens and [c++] renders as a reference link.

Actual Behavior

Muya#init throws Invalid regular expression: /\[c++\](?!:)/: Nothing to repeat and the document does not load.

Screenshots / Logs

Reproduced on develop (b0079e1f) by loading the document through Muya#init under vitest + happy-dom. Not yet reproduced in a packaged build.

Operating System

Linux (Other)

MarkText Version

develop @ b0079e1f (0.20.0-dev)

OS Version

Arch Linux, kernel 7.2.7

Reproducibility

  • I can reliably reproduce this issue