Bug 1020170

Summary: markdown.markdown fails with leading '<' character
Product: Red Hat Enterprise Linux 6 Reporter: Nick Coghlan <ncoghlan>
Component: python-markdownAssignee: Lumír Balhar <lbalhar>
Status: CLOSED ERRATA QA Contact: Jan Kepler <jkejda>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.6CC: bnater, cstratak, dcallagh, ebaak, jkejda, lbalhar, ncoghlan, pviktori, qwan, tools-bugs, xtian
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-markdown-2.0.1-4.el6 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1020153 Environment:
Last Closed: 2017-03-21 11:42:46 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Nick Coghlan 2013-10-17 07:56:29 UTC
+++ This bug was initially created as a clone of Bug #1020153 +++

Beaker (http://beaker-project.org) recently started supporting the use of markdown in system note fields. HSS QE discovered that starting a note with a "<" caused a 500 internal server error, and traced it back to this failure in the markdown renderer on RHEL6:

Python 2.6.6 (r266:84292, May 27 2013, 05:35:12) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from markdown import markdown
>>> markdown('<')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/markdown/__init__.py", line 587, in markdown
    return md.convert(text)
  File "/usr/lib/python2.6/site-packages/markdown/__init__.py", line 386, in convert
    self.lines = prep.run(self.lines)
  File "/usr/lib/python2.6/site-packages/markdown/preprocessors.py", line 128, in run
    left_tag = self._get_left_tag(block)
  File "/usr/lib/python2.6/site-packages/markdown/preprocessors.py", line 82, in _get_left_tag
    return block[1:].replace(">", " ", 1).split()[0].lower()
IndexError: list index out of range
>>> 
-bash-4.1$ rpm -qa python-markdown
python-markdown-2.0.1-3.1.el6.noarch

On Fedora, the more recent version of python-markdown handles this correctly:

Python 2.7.3 (default, Aug  9 2012, 17:23:57) 
[GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from markdown import markdown
>>> markdown("<")
u'<p>&lt;</p>'
>>> 
[ncoghlan@dhcp-41-79 beaker]$ rpm -qa python-markdown
python-markdown-2.2.1-1.fc18.noarch

The relevant issue and patch appear to be:

* https://github.com/waylan/Python-Markdown/issues/70
* https://github.com/waylan/Python-Markdown/commit/07bc7a4c8f2e834e0f8150de004c1f8fd98a3d60

Comment 8 errata-xmlrpc 2017-03-21 11:42:46 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2017-0773.html