Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow square brackets in reference link ids.
Browse files Browse the repository at this point in the history
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 Python-Markdown#1209.
waylan committed Jan 10, 2022
1 parent 1d41f13 commit b7c1c1a
Showing 3 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/change_log/index.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@ title: Change Log
Python-Markdown Change Log
=========================

(under development): version 3.3.7 (a bug-fix release).

* Disallow square brackets in reference link ids (#1209).

Nov 17, 2021: version 3.3.6 (a bug-fix release).

* Fix a dependency issue (#1195, #1196).
2 changes: 1 addition & 1 deletion markdown/blockprocessors.py
Original file line number Diff line number Diff line change
@@ -559,7 +559,7 @@ def run(self, parent, blocks):
class ReferenceProcessor(BlockProcessor):
""" Process link references. """
RE = re.compile(
r'^[ ]{0,3}\[([^\]]*)\]:[ ]*\n?[ ]*([^\s]+)[ ]*(?:\n[ ]*)?((["\'])(.*)\4[ ]*|\((.*)\)[ ]*)?$', re.MULTILINE
r'^[ ]{0,3}\[([^\[\]]*)\]:[ ]*\n?[ ]*([^\s]+)[ ]*(?:\n[ ]*)?((["\'])(.*)\4[ ]*|\((.*)\)[ ]*)?$', re.MULTILINE
)

def test(self, parent, block):
34 changes: 34 additions & 0 deletions tests/test_syntax/inline/test_links.py
Original file line number Diff line number Diff line change
@@ -350,3 +350,37 @@ def test_reference_across_blocks(self):
'<p>I would like to tell you about the [code of</p>\n'
'<p>conduct][] we are using in this project.</p>'
)

def test_ref_link_nested_left_bracket(self):
self.assertMarkdownRenders(
self.dedent(
"""
[Text[]
[Text[]: http://example.com
"""
),
self.dedent(
"""
<p>[Text[]</p>
<p>[Text[]: http://example.com</p>
"""
)
)

def test_ref_link_nested_right_bracket(self):
self.assertMarkdownRenders(
self.dedent(
"""
[Text]]
[Text]]: http://example.com
"""
),
self.dedent(
"""
<p>[Text]]</p>
<p>[Text]]: http://example.com</p>
"""
)
)

0 comments on commit b7c1c1a

Please sign in to comment.