Skip to content

Commit af38c42

Browse files
committed
Disallow square brackets in reference link ids.
We already disallow right square brackets. This also disallows left square brackets, which ensures link references will be less likely to collide with standard links in some weird edge cases. Fixes #1209.
1 parent 1d41f13 commit af38c42

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

docs/change_log/index.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ title: Change Log
33
Python-Markdown Change Log
44
=========================
55

6+
(under development): version 3.3.7 (a bug-fix release).
7+
8+
* Disallow square brackets in reference link ids (#1209).
9+
610
Nov 17, 2021: version 3.3.6 (a bug-fix release).
711

812
* Fix a dependency issue (#1195, #1196).

markdown/blockprocessors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def run(self, parent, blocks):
559559
class ReferenceProcessor(BlockProcessor):
560560
""" Process link references. """
561561
RE = re.compile(
562-
r'^[ ]{0,3}\[([^\]]*)\]:[ ]*\n?[ ]*([^\s]+)[ ]*(?:\n[ ]*)?((["\'])(.*)\4[ ]*|\((.*)\)[ ]*)?$', re.MULTILINE
562+
r'^[ ]{0,3}\[([^\[\]]*)\]:[ ]*\n?[ ]*([^\s]+)[ ]*(?:\n[ ]*)?((["\'])(.*)\4[ ]*|\((.*)\)[ ]*)?$', re.MULTILINE
563563
)
564564

565565
def test(self, parent, block):

tests/test_syntax/inline/test_links.py

+34
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,37 @@ def test_reference_across_blocks(self):
350350
'<p>I would like to tell you about the [code of</p>\n'
351351
'<p>conduct][] we are using in this project.</p>'
352352
)
353+
354+
def test_ref_link_nested_left_bracket(self):
355+
self.assertMarkdownRenders(
356+
self.dedent(
357+
"""
358+
[Text[]
359+
360+
[Text[]: http://example.com
361+
"""
362+
),
363+
self.dedent(
364+
"""
365+
<p>[Text[]</p>
366+
<p>[Text[]: http://example.com</p>
367+
"""
368+
)
369+
)
370+
371+
def test_ref_link_nested_right_bracket(self):
372+
self.assertMarkdownRenders(
373+
self.dedent(
374+
"""
375+
[Text]]
376+
377+
[Text]]: http://example.com
378+
"""
379+
),
380+
self.dedent(
381+
"""
382+
<p>[Text]]</p>
383+
<p>[Text]]: http://example.com</p>
384+
"""
385+
)
386+
)

0 commit comments

Comments
 (0)