|
ticket id 000054 |
status closed |
priority ??? |
assigned to NOBODY |
Reported by: Ben Thorp Component: |
One of my users found a weird bug when entering some Markdown in a Django form. If you include more spaces after the bullet than in the markdown tab length, then the blockparser throws an error. (IndexError: child index out of range)
To replicate:
- Check markdown.TAB_LENGTH
- Enter text starting with a bullet and then more spaces than in the TAB_LENGTH
- Try to run it through markdown
(Note in below example there are 5 fives between * and test in the first line)
>>> text = '* test'
>>> markdown.markdown(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.5/site-packages/markdown/__init__.py", line 587, in markdown
return md.convert(text)
File "/Library/Python/2.5/site-packages/markdown/__init__.py", line 389, in convert
root = self.parser.parseDocument(self.lines).getroot()
File "/Library/Python/2.5/site-packages/markdown/blockparser.py", line 60, in parseDocument
self.parseChunk(self.root, '\n'.join(lines))
File "/Library/Python/2.5/site-packages/markdown/blockparser.py", line 75, in parseChunk
self.parseBlocks(parent, text.split('\n\n'))
File "/Library/Python/2.5/site-packages/markdown/blockparser.py", line 92, in parseBlocks
processor.run(parent, blocks)
File "/Library/Python/2.5/site-packages/markdown/blockprocessors.py", line 295, in run
self.parser.parseBlocks(lst[-1], [item])
IndexError: child index out of range
>>> markdown.TAB_LENGTH
4
>>> markdown.TAB_LENGTH = 7
>>> markdown.markdown(text)
u'<ul>\n<li>test</li>\n</ul>'
>>>
UPDATE The problem appears to be that it sees the spaces as being indentation and assumes it has a parent because the indentation is there. (Not sure why it's not checking the indentation before the *, but I didn't look far enough). Adding a check to blockprocessors.py seems to fix it:
line 293:
if ((item.startswith(' '*markdown.TAB_LENGTH)) and (len(lst) > 0)):
at least, it doesn't throw an error, although you then run into my other ticket about it creating a paragraph, rather than list items.
IGNORE ME I hadn't upgraded to 2.0.3
Resolution
n.a.