| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -139,7 +139,15 @@ def goahead(self, end): | |||
| 139 | 139 | if self.convert_charrefs and not self.cdata_elem: | |
| 140 | 140 | j = rawdata.find('<', i) | |
| 141 | 141 | if j < 0: | |
| 142 | - if not end: | ||
| 142 | + # if we can't find the next <, either we are at the end | ||
| 143 | + # or there's more text incoming. If the latter is True, | ||
| 144 | + # we can't pass the text to handle_data in case we have | ||
| 145 | + # a charref cut in half at end. Try to determine if | ||
| 146 | + # this is the case before proceding by looking for an | ||
| 147 | + # & near the end and see if it's followed by a space or ;. | ||
| 148 | + amppos = rawdata.rfind('&', max(i, n-34)) | ||
| 149 | + if (amppos >= 0 and | ||
| 150 | + not re.compile(r'[\s;]').search(rawdata, amppos)): | ||
| 143 | 151 | break # wait till we get all the text | |
| 144 | 152 | j = n | |
| 145 | 153 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,9 +72,6 @@ def handle_starttag(self, tag, attrs): | |||
| 72 | 72 | ||
| 73 | 73 | class EventCollectorCharrefs(EventCollector): | |
| 74 | 74 | ||
| 75 | - def get_events(self): | ||
| 76 | - return self.events | ||
| 77 | - | ||
| 78 | 75 | def handle_charref(self, data): | |
| 79 | 76 | self.fail('This should never be called with convert_charrefs=True') | |
| 80 | 77 | ||
@@ -633,6 +630,18 @@ def test_broken_condcoms(self): | |||
| 633 | 630 | ] | |
| 634 | 631 | self._run_check(html, expected) | |
| 635 | 632 | ||
| 633 | + def test_convert_charrefs_dropped_text(self): | ||
| 634 | + # #23144: make sure that all the events are triggered when | ||
| 635 | + # convert_charrefs is True, even if we don't call .close() | ||
| 636 | + parser = EventCollector(convert_charrefs=True) | ||
| 637 | + # before the fix, bar & baz was missing | ||
| 638 | + parser.feed("foo <a>link</a> bar & baz") | ||
| 639 | + self.assertEqual( | ||
| 640 | + parser.get_events(), | ||
| 641 | + [('data', 'foo '), ('starttag', 'a', []), ('data', 'link'), | ||
| 642 | + ('endtag', 'a'), ('data', ' bar & baz')] | ||
| 643 | + ) | ||
| 644 | + | ||
| 636 | 645 | ||
| 637 | 646 | class AttributesTestCase(TestCaseBase): | |
| 638 | 647 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - +++++++++++ | ||
| 1 | + +++++++++++ | ||
| 2 | 2 | Python News | |
| 3 | 3 | +++++++++++ | |
| 4 | 4 | ||
@@ -95,9 +95,13 @@ Core and Builtins | |||
| 95 | 95 | Library | |
| 96 | 96 | ------- | |
| 97 | 97 | ||
| 98 | + - Issue #23144: Make sure that HTMLParser.feed() returns all the data, even | ||
| 99 | + when convert_charrefs is True. | ||
| 100 | + | ||
| 98 | 101 | - Issue #24635: Fixed a bug in typing.py where isinstance([], typing.Iterable) | |
| 99 | 102 | would return True once, then False on subsequent calls. | |
| 100 | 103 | ||
| 104 | + | ||
| 101 | 105 | - Issue #24989: Fixed buffer overread in BytesIO.readline() if a position is | |
| 102 | 106 | set beyond size. Based on patch by John Leitch. | |
| 103 | 107 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments