Skip to content

Commit edb0143

Browse files
committed
👌 IMPROVE: Link validation
- Disallow escaped spaces inside link destination: `[](url\ xxx)` no longer valid (implements: markdown-it/markdown-it@2290e10) - Stop link title parsing when second `(` is found: `[](url (xxx())` no longer valid (implements: markdown-it/markdown-it@b1651b1) - Stop link parsing when second `<` is found: `[](<foo<bar>)` (implements: markdown-it/markdown-it@f688abc)
1 parent ccb930e commit edb0143

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

markdown_it/helpers/parse_link_destination.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def parseLinkDestination(string: str, pos: int, maximum: int) -> _Result:
2626
code = charCodeAt(string, pos)
2727
if code == 0x0A: # /* \n */)
2828
return result
29+
if code == 0x3C: # / * < * /
30+
return result
2931
if code == 0x3E: # /* > */) {
3032
result.pos = pos + 1
3133
result.str = unescapeAll(string[start + 1 : pos])
@@ -55,6 +57,8 @@ def parseLinkDestination(string: str, pos: int, maximum: int) -> _Result:
5557
break
5658

5759
if code == 0x5C and pos + 1 < maximum:
60+
if charCodeAt(string, pos + 1) == 0x20:
61+
break
5862
pos += 2
5963
continue
6064

markdown_it/helpers/parse_link_title.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def parseLinkTitle(string: str, pos: int, maximum: int) -> _Result:
4646
result.str = title
4747
result.ok = True
4848
return result
49+
elif code == 0x28 and marker == 0x29: # /* ( */ /* ) */
50+
return result
4951
elif code == 0x0A:
5052
lines += 1
5153
elif code == 0x5C and pos + 1 < maximum: # /* \ */

tests/test_port/fixtures/commonmark_extras.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,33 @@ List item terminating quote should not be paragraph continuation
255255
</ol>
256256
.
257257

258+
Escaped space is not allowed in link destination, commonmark/CommonMark#493.
259+
.
260+
[link](a\ b)
261+
.
262+
<p>[link](a\ b)</p>
263+
.
264+
265+
Link destination cannot contain '<'
266+
.
267+
[](<foo<bar>)
268+
269+
[](<foo\<bar>)
270+
.
271+
<p>[](&lt;foo<bar>)</p>
272+
<p><a href="foo%3Cbar"></a></p>
273+
.
274+
275+
Link title cannot contain '(' when opened with it
276+
.
277+
[](url (xxx())
278+
279+
[](url (xxx\())
280+
.
281+
<p>[](url (xxx())</p>
282+
<p><a href="url" title="xxx("></a></p>
283+
.
284+
258285
Allow EOL in processing instructions, commonmark/commonmark.js#196.
259286
.
260287
a <?

0 commit comments

Comments
 (0)