Skip to content

Commit 594b25d

Browse files
facelessuserwaylan
authored andcommitted
Fix hr recursion issue (#535)
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.
1 parent 4a3d1a6 commit 594b25d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

markdown/blockprocessors.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,15 +493,16 @@ def test(self, parent, block):
493493

494494
def run(self, parent, blocks):
495495
block = blocks.pop(0)
496+
match = self.match
496497
# Check for lines in block before hr.
497-
prelines = block[:self.match.start()].rstrip('\n')
498+
prelines = block[:match.start()].rstrip('\n')
498499
if prelines:
499500
# Recursively parse lines before hr so they get parsed first.
500501
self.parser.parseBlocks(parent, [prelines])
501502
# create hr
502503
util.etree.SubElement(parent, 'hr')
503504
# check for lines in block after hr.
504-
postlines = block[self.match.end():].lstrip('\n')
505+
postlines = block[match.end():].lstrip('\n')
505506
if postlines:
506507
# Add lines after hr to master blocks for later parsing.
507508
blocks.insert(0, postlines)

tests/misc/blockquote-hr.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,13 @@
1313
Even a lazy line.</p>
1414
<hr />
1515
<p>The last line.</p>
16+
</blockquote>
17+
<p>foo</p>
18+
<blockquote>
19+
<p>bar</p>
20+
<hr />
21+
</blockquote>
22+
<hr />
23+
<blockquote>
24+
<p>baz</p>
1625
</blockquote>

tests/misc/blockquote-hr.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ Even a lazy line.
1919
> ---
2020

2121
> The last line.
22+
23+
foo
24+
> bar
25+
> ***
26+
---
27+
> baz

0 commit comments

Comments
 (0)