fix: allow one more level of nested brackets in a link label (#4064)

This commit is contained in:
Luan Taraschi
2026-09-03 23:59:25 -06:00
committed by GitHub
parent 8f432f0ef2
commit 37b28d8f64
3 changed files with 14 additions and 13 deletions
+8 -1
View File
@@ -441,7 +441,14 @@ const tag = edit(
.replace('attribute', /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/)
.getRegex();
const _inlineLabel = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/;
// One matched pair of brackets, holding no bracket of its own.
const _inlineLabelBrackets = /\[(?:\\[\s\S]|[^\[\]\\])*\]/;
// CommonMark lets the brackets in a link label nest to any depth, which a regex
// cannot follow, so it stops at a fixed one. Two levels is what the spec suite
// asks for: a third and a fourth flip no further example.
const _inlineLabel = edit(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/)
.replace('brackets', _inlineLabelBrackets)
.getRegex();
const link = edit(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/)
.replace('label', _inlineLabel)
+3 -6
View File
@@ -4096,8 +4096,7 @@
"example": 512,
"start_line": 7840,
"end_line": 7844,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link] bar](/uri)\n",
@@ -4161,8 +4160,7 @@
"example": 520,
"start_line": 7900,
"end_line": 7904,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "*[foo*](/uri)\n",
@@ -4228,8 +4226,7 @@
"example": 528,
"start_line": 8004,
"end_line": 8010,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link \\[bar][ref]\n\n[ref]: /uri\n",
+3 -6
View File
@@ -4096,8 +4096,7 @@
"example": 512,
"start_line": 7840,
"end_line": 7844,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link] bar](/uri)\n",
@@ -4161,8 +4160,7 @@
"example": 520,
"start_line": 7900,
"end_line": 7904,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "*[foo*](/uri)\n",
@@ -4228,8 +4226,7 @@
"example": 528,
"start_line": 8004,
"end_line": 8010,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link \\[bar][ref]\n\n[ref]: /uri\n",