From 594b25d53798c30735da5a9be19c06cc94052a16 Mon Sep 17 00:00:00 2001 From: Isaac Muse Date: Mon, 23 Jan 2017 09:10:20 -0700 Subject: [PATCH] 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. --- markdown/blockprocessors.py | 5 +++-- tests/misc/blockquote-hr.html | 9 +++++++++ tests/misc/blockquote-hr.txt | 6 ++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 870151bec..a3ed97794 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -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) diff --git a/tests/misc/blockquote-hr.html b/tests/misc/blockquote-hr.html index 61c1a3c54..e13784f42 100644 --- a/tests/misc/blockquote-hr.html +++ b/tests/misc/blockquote-hr.html @@ -13,4 +13,13 @@ Even a lazy line.


The last line.

+ +

foo

+
+

bar

+
+
+
+
+

baz

\ No newline at end of file diff --git a/tests/misc/blockquote-hr.txt b/tests/misc/blockquote-hr.txt index ef9c44fb4..8f67b242d 100644 --- a/tests/misc/blockquote-hr.txt +++ b/tests/misc/blockquote-hr.txt @@ -19,3 +19,9 @@ Even a lazy line. > --- > The last line. + +foo +> bar +> *** +--- +> baz