Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.74k stars 858 forks source link

Fix edge-case crash in codehilite #1405

Closed oprypin closed 10 months ago

oprypin commented 10 months ago

If there is an empty <pre><code></code></pre> inserted by another extension, there can be an exception. The added test case was crashing before this change:

  File "markdown/core.py", line 361, in convert
    newRoot = treeprocessor.run(root)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "markdown/extensions/codehilite.py", line 274, in run
    self.code_unescape(block[0].text),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "markdown/extensions/codehilite.py", line 260, in code_unescape
    text = text.replace("&lt;", "<")
           ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'replace'