Skip to content

Commit

Permalink
[3.9] bpo-34480: fix bug where match variable is used prior to being …
Browse files Browse the repository at this point in the history
…defined (GH-17643) (GH-32256)

Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
  • Loading branch information
4 people committed May 16, 2022
1 parent 1699a5e commit 518b238
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions Lib/_markupbase.py
Expand Up @@ -157,6 +157,7 @@ def parse_marked_section(self, i, report=1):
match= _msmarkedsectionclose.search(rawdata, i+3)
else:
self.error('unknown status keyword %r in marked section' % rawdata[i+3:j])
match = None
if not match:
return -1
if report:
Expand Down
22 changes: 22 additions & 0 deletions Lib/test/test_htmlparser.py
Expand Up @@ -787,5 +787,27 @@ def test_weird_chars_in_unquoted_attribute_values(self):
('starttag', 'form',
[('action', 'bogus|&#()value')])])

def test_invalid_keyword_error_exception(self):
# bpo-34480: check that subclasses that define an
# error method that raises an exception work
class InvalidMarkupException(Exception):
pass
class MyHTMLParser(html.parser.HTMLParser):
def error(self, message):
raise InvalidMarkupException(message)
parser = MyHTMLParser()
with self.assertRaises(InvalidMarkupException):
parser.feed('<![invalid>')

def test_invalid_keyword_error_pass(self):
# bpo-34480: check that subclasses that define an
# error method that doesn't raise an exception work
class MyHTMLParser(html.parser.HTMLParser):
def error(self, message):
pass
parser = MyHTMLParser()
self.assertEqual(parser.feed('<![invalid>'), None)


if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,3 @@
Fix a bug where :mod:`_markupbase` raised an :exc:`UnboundLocalError`
when an invalid keyword was found in marked section. Patch by Marek
Suscak.

0 comments on commit 518b238

Please sign in to comment.