fix(markdown): balanced parentheses inside autolinks (#41)

This commit is contained in:
hampus-fluxer
2026-01-06 03:19:13 +01:00
committed by GitHub
parent 39ac149810
commit 1ed066ca36
2 changed files with 42 additions and 3 deletions

View File

@@ -314,10 +314,31 @@ export function extractUrlSegment(text: string, parserFlags: number): ParserResu
let end = prefixLength;
const textLength = text.length;
let parenthesesDepth = 0;
while (end < textLength && !StringUtils.isUrlTerminationChar(text[end])) {
end++;
if (end - prefixLength > MAX_LINK_URL_LENGTH) break;
while (end < textLength) {
const currentChar = text[end];
if (currentChar === '(') {
parenthesesDepth++;
end++;
} else if (currentChar === ')') {
if (parenthesesDepth > 0) {
parenthesesDepth--;
end++;
} else {
break;
}
} else if (StringUtils.isUrlTerminationChar(currentChar)) {
break;
} else {
end++;
}
if (end - prefixLength > MAX_LINK_URL_LENGTH) {
end = prefixLength + MAX_LINK_URL_LENGTH;
break;
}
}
let urlString = text.slice(0, end);