Skip to content

Commit 4c0534e

Browse files
Merge pull request #650 from Crozzers/fix-empty-links-breaking-backslash-escape
Fix empty links breaking backslash newlines (#648)
2 parents 9a88ce1 + 1beb3c2 commit 4c0534e

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

lib/markdown2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,10 @@ def _protect_url(self, url: str) -> str:
14641464
and then hashes the now "safe" URL to prevent other safety mechanisms from tampering
14651465
with it (eg: escaping "&" in URL parameters)
14661466
'''
1467+
if not url:
1468+
# ignore links with empty URLs. Don't bother putting a hash there because then we'll have
1469+
# `"''"": "md5-..."` as an entry in the escape table, and that will cause havok
1470+
return url
14671471
data_url = self._data_url_re.match(url)
14681472
charset = None
14691473
if data_url is not None:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p><a href="">link</a></p>
2+
3+
<p>one<br />
4+
two</p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"extras": {"breaks": {"on_backslash": True}}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[link]()
2+
3+
one\
4+
two

0 commit comments

Comments
 (0)