Skip to content

Commit b5dd994

Browse files
authored
Merge pull request #465 from chuenchen309/fix/angle-link-href-backslash
2 parents 89cbd56 + e12f0d3 commit b5dd994

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/mistune/helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ def _parse_angle_link_href(src: str, pos: int) -> Union[Tuple[str, int], Tuple[N
266266
c = src[pos]
267267
if c == ">":
268268
return src[start:pos], pos + 1
269-
if c in "<\\\n\r\x00":
269+
if c == "\\":
270+
pos = min(pos + 2, len(src))
271+
continue
272+
if c in "<\n\r\x00":
270273
return None, None
271274
pos += 1
272275
return None, None

tests/test_misc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ def test_link_bracket_cache_cases(self):
148148
for text, html in cases.items():
149149
self.assertEqual(mistune.html(text).strip(), html)
150150

151+
def test_angle_link_escaped_backslash(self):
152+
cases = {
153+
r"[link](<foo\*bar>)": '<p><a href="foo*bar">link</a></p>',
154+
"[x]: <a\\*b>\n\n[x]": '<p><a href="a*b">x</a></p>',
155+
}
156+
for text, html in cases.items():
157+
self.assertEqual(mistune.html(text).strip(), html, text)
158+
151159
def test_allow_harmful_protocols(self):
152160
renderer = mistune.HTMLRenderer(allow_harmful_protocols=True)
153161
md = mistune.Markdown(renderer)

0 commit comments

Comments
 (0)