diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2015-09-06 18:38:06 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2015-09-06 18:38:06 (GMT) |
commit | 6f2bb98966853edcf1855b9dd310529d071241a2 (patch) | |
tree | 088d7d3cdd103b5b01a6d9c081ec3b40fcd110bd /Lib/html/parser.py | |
parent | 527ef0792f79fda93f568830bba396b22fbcec6a (diff) | |
download | cpython-6f2bb98966853edcf1855b9dd310529d071241a2.zip cpython-6f2bb98966853edcf1855b9dd310529d071241a2.tar.gz cpython-6f2bb98966853edcf1855b9dd310529d071241a2.tar.bz2 |
#23144: Make sure that HTMLParser.feed() returns all the data, even when convert_charrefs is True.
Diffstat (limited to 'Lib/html/parser.py')
-rw-r--r-- | Lib/html/parser.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/html/parser.py b/Lib/html/parser.py index a650d5e..9ae31b9 100644 --- a/Lib/html/parser.py +++ b/Lib/html/parser.py @@ -198,7 +198,15 @@ class HTMLParser(_markupbase.ParserBase): if self.convert_charrefs and not self.cdata_elem: j = rawdata.find('<', i) if j < 0: - if not end: + # if we can't find the next <, either we are at the end + # or there's more text incoming. If the latter is True, + # we can't pass the text to handle_data in case we have + # a charref cut in half at end. Try to determine if + # this is the case before proceding by looking for an + # & near the end and see if it's followed by a space or ;. + amppos = rawdata.rfind('&', max(i, n-34)) + if (amppos >= 0 and + not re.compile(r'[\s;]').search(rawdata, amppos)): break # wait till we get all the text j = n else: |