Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e596a7

Browse files
committed
#17802: Fix an UnboundLocalError in html.parser. Initial tests by Thomas Barlow.
1 parent a771a1b commit 8e596a7

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lib/html/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def goahead(self, end):
249249
if self.strict:
250250
self.error("EOF in middle of entity or char ref")
251251
else:
252+
k = match.end()
252253
if k <= i:
253254
k = n
254255
i = self.updatepos(i, i + 1)

Lib/test/test_htmlparser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,20 @@ def test_correct_detection_of_start_tags(self):
535535
]
536536
self._run_check(html, expected)
537537

538+
def test_EOF_in_charref(self):
539+
# see #17802
540+
# This test checks that the UnboundLocalError reported in the issue
541+
# is not raised, however I'm not sure the returned values are correct.
542+
# Maybe HTMLParser should use self.unescape for these
543+
data = [
544+
('a&', [('data', 'a&')]),
545+
('a&b', [('data', 'ab')]),
546+
('a&b ', [('data', 'a'), ('entityref', 'b'), ('data', ' ')]),
547+
('a&b;', [('data', 'a'), ('entityref', 'b')]),
548+
]
549+
for html, expected in data:
550+
self._run_check(html, expected)
551+
538552
def test_unescape_function(self):
539553
p = self.get_collector()
540554
self.assertEqual(p.unescape('&#bad;'),'&#bad;')

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Core and Builtins
4444
Library
4545
-------
4646

47+
- Issue #17802: Fix an UnboundLocalError in html.parser. Initial tests by
48+
Thomas Barlow.
49+
4750
- Issue #17192: Restore the patch for Issue #11729 which was ommitted in
4851
3.3.1 when updating the bundled version of libffi used by ctypes. Update
4952
many libffi files that were missed in 3.3.1's update to libffi-3.0.13.

0 commit comments

Comments
 (0)