Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6f2bb989
Commit
6f2bb989
authored
Sep 06, 2015
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#23144: Make sure that HTMLParser.feed() returns all the data, even when convert_charrefs is True.
parent
527ef079
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
5 deletions
+25
-5
Lib/html/parser.py
Lib/html/parser.py
+9
-1
Lib/test/test_htmlparser.py
Lib/test/test_htmlparser.py
+12
-3
Misc/NEWS
Misc/NEWS
+4
-1
No files found.
Lib/html/parser.py
View file @
6f2bb989
...
...
@@ -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:
...
...
Lib/test/test_htmlparser.py
View file @
6f2bb989
...
...
@@ -72,9 +72,6 @@ class EventCollectorExtra(EventCollector):
class
EventCollectorCharrefs
(
EventCollector
):
def
get_events
(
self
):
return
self
.
events
def
handle_charref
(
self
,
data
):
self
.
fail
(
'This should never be called with convert_charrefs=True'
)
...
...
@@ -685,6 +682,18 @@ class HTMLParserTolerantTestCase(HTMLParserStrictTestCase):
]
self
.
_run_check
(
html
,
expected
)
def
test_convert_charrefs_dropped_text
(
self
):
# #23144: make sure that all the events are triggered when
# convert_charrefs is True, even if we don't call .close()
parser
=
EventCollector
(
convert_charrefs
=
True
)
# before the fix, bar & baz was missing
parser
.
feed
(
"foo <a>link</a> bar & baz"
)
self
.
assertEqual
(
parser
.
get_events
(),
[(
'data'
,
'foo '
),
(
'starttag'
,
'a'
,
[]),
(
'data'
,
'link'
),
(
'endtag'
,
'a'
),
(
'data'
,
' bar & baz'
)]
)
class
AttributesStrictTestCase
(
TestCaseBase
):
...
...
Misc/NEWS
View file @
6f2bb989
+++++++++++
+++++++++++
Python
News
+++++++++++
...
...
@@ -81,6 +81,9 @@ Core and Builtins
Library
-------
-
Issue
#
23144
:
Make
sure
that
HTMLParser
.
feed
()
returns
all
the
data
,
even
when
convert_charrefs
is
True
.
-
Issue
#
16180
:
Exit
pdb
if
file
has
syntax
error
,
instead
of
trapping
user
in
an
infinite
loop
.
Patch
by
Xavier
de
Gaye
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment