Skip to content

Disallow square brackets in reference link ids. #1210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/change_log/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion markdown/blockprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 34 additions & 0 deletions tests/test_syntax/inline/test_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>
"""
)
)