fix: reject a link destination in angle brackets with an unescaped < or > (#4206)

This commit is contained in:
yash
2026-11-16 09:29:19 -07:00
committed by GitHub
parent 0460f98b7e
commit de71210d42
3 changed files with 22 additions and 2 deletions
+2 -2
View File
@@ -163,7 +163,7 @@ const lheadingGfm = edit(lheadingCore)
const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/;
const blockText = /^[^\n]+/;
const _blockLabel = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\\n]|\n(?![ \t]*\n))+/;
const def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/)
const def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<(?:\\.|[^\n<>\\])*>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/)
.replace('label', _blockLabel)
// An escaped delimiter is part of the title, so a backslash must consume the
// next character. An optional closer (`\"?`) lets that character backtrack
@@ -488,7 +488,7 @@ const _inlineLabel = edit(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?
const link = edit(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/)
.replace('label', _inlineLabel)
.replace('href', /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/)
.replace('href', /<(?:\\.|[^\n<>\\])*>|(?!<)[^ \t\n\x00-\x1f]+|(?=\))/)
// Same as the definition title: the escaped character is not the closer.
.replace('title', /"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*'|\((?:\\[\s\S]|[^)\\])*\)/)
.getRegex();
@@ -0,0 +1,7 @@
<p>[a](&lt;b<c>)</p>
<p>[a](<b>c&gt;)</p>
<p>[a](<b>&gt;)</p>
<p>![i](&lt;x<y>)</p>
<p><a href="b%3Cc" title="t">a</a></p>
<p>[r]: &lt;x<y></p>
<p>[r]</p>
@@ -0,0 +1,13 @@
[a](<b<c>)
[a](<b>c>)
[a](<b>>)
![i](<x<y>)
[a](<b\<c> "t")
[r]: <x<y>
[r]