8000 [3.9] bpo-34480: fix bug where match variable is used prior to being … · varunsh-coder/cpython@518b238 · GitHub
[go: up one dir, main page]

Skip to content

Commit 518b238

Browse files
mareksuscakezio-melottiblurb-it[bot]ambv
authored
[3.9] bpo-34480: fix bug where match variable is used prior to being defined (pythonGH-17643) (pythonGH-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>
1 parent 1699a5e commit 518b238

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Lib/_markupbase.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def parse_marked_section(self, i, report=1):
157157
match= _msmarkedsectionclose.search(rawdata, i+3)
158158
else:
159159
self.error('unknown status keyword %r in marked section' % rawdata[i+3:j])
160+
match = None
160161
if not match:
161162
return -1
162163
if report:

Lib/test/test_htmlparser.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,5 +787,27 @@ def test_weird_chars_in_unquoted_attribute_values(self):
787787
('starttag', 'form',
788788
[('action', 'bogus|&#()value')])])
789789

790+
def test_invalid_keyword_error_exception(self):
791+
# bpo-34480: check that subclasses that define an
792+
# error method that raises an exception work
793+
class InvalidMarkupException(Exception):
794+
pass
795+
class MyHTMLParser(html.parser.HTMLParser):
796+
def error(self, message):
797+
raise InvalidMarkupException(message)
798+
parser = MyHTMLParser()
799+
with self.assertRaises(InvalidMarkupException):
800+
parser.feed('<![invalid>')
801+
802+
def test_invalid_keyword_error_pass(self):
803+
# bpo-34480: check that subclasses that define an
804+
# error method that doesn't raise an exception work
805+
class MyHTMLParser(html.parser.HTMLParser):
806+
def error(self, message):
807+
pass
808+
parser = MyHTMLParser()
809+
self.assertEqual(parser.feed('<![invalid>'), None)
810+
811+
790812
if __name__ == "__main__":
791813
unittest.main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a bug where :mod:`_markupbase` raised an :exc:`UnboundLocalError`
2+
when an invalid keyword was found in marked section. Patch by Marek
3+
Suscak.

0 commit comments

Comments
 (0)
0