fix: fix link url with no closing parenthesis (#3664)

* fix: fix link url with no closing parenthesis

* add escape test

* add double escape
This commit is contained in:
Tony Brix 2025-04-21 17:03:37 -06:00 committed by GitHub
parent d5e5f8fbbc
commit 72b63739f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 25 additions and 4 deletions

View File

@ -636,6 +636,11 @@ export class _Tokenizer {
} else {
// find closing parenthesis
const lastParenIndex = findClosingBracket(cap[2], '()');
if (lastParenIndex === -2) {
// more open parens than closed
return;
}
if (lastParenIndex > -1) {
const start = cap[0].indexOf('!') === 0 ? 5 : 4;
const linkLen = start + cap[1].length + lastParenIndex;

View File

@ -141,5 +141,9 @@ export function findClosingBracket(str: string, b: string) {
}
}
}
if (level > 0) {
return -2;
}
return -1;
}

View File

@ -3975,8 +3975,7 @@
"example": 497,
"start_line": 7666,
"end_line": 7670,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link](foo\\(and\\(bar\\))\n",

View File

@ -3975,8 +3975,7 @@
"example": 497,
"start_line": 7666,
"end_line": 7670,
"section": "Links",
"shouldFail": true
"section": "Links"
},
{
"markdown": "[link](foo\\(and\\(bar\\))\n",

View File

@ -0,0 +1,7 @@
<p>[link](foo(bar())</p>
<p><a href="foo(bar()">link</a></p>
<p><a href="foo(bar()">link</a></p>
<p>[link](foo(bar\())</p>

View File

@ -0,0 +1,7 @@
[link](foo(bar())
[link](foo\(bar())
[link](foo(bar\())
[link](foo(bar\\())