Skip to content

Commit

Permalink
Fix hr recursion issue (Python-Markdown#535)
Browse files Browse the repository at this point in the history
HRProcessor tried to access a member variable after recursively calling
itself.  In certain situations HRProcessor will try to access its
member variable containing its match, but it will not be the same match
that call in the stack expected.  This is easily fixed by storing the
match locally *before* doing any recursive work.
  • Loading branch information
facelessuser authored and waylan committed Jan 23, 2017
1 parent 4a3d1a6 commit 594b25d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions markdown/blockprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,16 @@ def test(self, parent, block):

def run(self, parent, blocks):
block = blocks.pop(0)
match = self.match
# Check for lines in block before hr.
prelines = block[:self.match.start()].rstrip('\n')
prelines = block[:match.start()].rstrip('\n')
if prelines:
# Recursively parse lines before hr so they get parsed first.
self.parser.parseBlocks(parent, [prelines])
# create hr
util.etree.SubElement(parent, 'hr')
# check for lines in block after hr.
postlines = block[self.match.end():].lstrip('\n')
postlines = block[match.end():].lstrip('\n')
if postlines:
# Add lines after hr to master blocks for later parsing.
blocks.insert(0, postlines)
Expand Down
9 changes: 9 additions & 0 deletions tests/misc/blockquote-hr.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@
Even a lazy line.</p>
<hr />
<p>The last line.</p>
</blockquote>
<p>foo</p>
<blockquote>
<p>bar</p>
<hr />
</blockquote>
<hr />
<blockquote>
<p>baz</p>
</blockquote>
6 changes: 6 additions & 0 deletions tests/misc/blockquote-hr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ Even a lazy line.
> ---

> The last line.

foo
> bar
> ***
---
> baz

0 comments on commit 594b25d

Please sign in to comment.