diff --git a/docs/change_log/index.md b/docs/change_log/index.md index 0a4e2f3d7..ca4792b1b 100644 --- a/docs/change_log/index.md +++ b/docs/change_log/index.md @@ -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). diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index dac3f086a..d901beb80 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -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): diff --git a/tests/test_syntax/inline/test_links.py b/tests/test_syntax/inline/test_links.py index 7a3e1c322..04587560d 100644 --- a/tests/test_syntax/inline/test_links.py +++ b/tests/test_syntax/inline/test_links.py @@ -350,3 +350,37 @@ def test_reference_across_blocks(self): '

I would like to tell you about the [code of

\n' '

conduct][] we are using in this project.

' ) + + def test_ref_link_nested_left_bracket(self): + self.assertMarkdownRenders( + self.dedent( + """ + [Text[] + + [Text[]: http://example.com + """ + ), + self.dedent( + """ +

[Text[]

+

[Text[]: http://example.com

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

[Text]]

+

[Text]]: http://example.com

+ """ + ) + )