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

Skip to content

Commit d9e0b06

Browse files
committed
#12888: Fix a bug in HTMLParser.unescape that prevented it to escape more than 128 entities. Patch by Peter Otten.
1 parent 73abc24 commit d9e0b06

4 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/html/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,4 @@ def replaceEntities(s):
458458
return '&'+s+';'
459459

460460
return re.sub(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));",
461-
replaceEntities, s, re.ASCII)
461+
replaceEntities, s, flags=re.ASCII)

Lib/test/test_htmlparser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ def test_unescape_function(self):
377377
p = html.parser.HTMLParser()
378378
self.assertEqual(p.unescape('&#bad;'),'&#bad;')
379379
self.assertEqual(p.unescape('&'),'&')
380-
380+
# see #12888
381+
self.assertEqual(p.unescape('{ ' * 1050), '{ ' * 1050)
381382

382383
def test_main():
383384
support.run_unittest(HTMLParserTestCase, HTMLParserTolerantTestCase)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ Douglas Orr
661661
Michele Orrù
662662
Oleg Oshmyan
663663
Denis S. Otkidach
664+
Peter Otten
664665
Michael Otteneder
665666
R. M. Oudkerk
666667
Russel Owen

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Core and Builtins
2525
Library
2626
-------
2727

28+
- Issue #12888: Fix a bug in HTMLParser.unescape that prevented it to escape
29+
more than 128 entities. Patch by Peter Otten.
30+
2831
- Issue #12878: Expose a __dict__ attribute on io.IOBase and its subclasses.
2932

3033
- Issue #12636: IDLE reads the coding cookie when executing a Python script.

0 commit comments

Comments
 (0)