mirror of
https://github.com/python/cpython.git
synced 2025-10-21 00:44:12 +00:00
gh-135661: Fix parsing unterminated bogus comments in HTMLParser (GH-137873)
Bogus comments that start with "<![CDATA[" should not include the starting "!" in its value.
This commit is contained in:
parent
eac37b46d9
commit
7636a66635
2 changed files with 9 additions and 15 deletions
|
@ -271,11 +271,8 @@ def goahead(self, end):
|
|||
j -= len(suffix)
|
||||
break
|
||||
self.handle_comment(rawdata[i+4:j])
|
||||
elif startswith("<![CDATA[", i):
|
||||
if self._support_cdata:
|
||||
self.unknown_decl(rawdata[i+3:])
|
||||
else:
|
||||
self.handle_comment(rawdata[i+1:])
|
||||
elif startswith("<![CDATA[", i) and self._support_cdata:
|
||||
self.unknown_decl(rawdata[i+3:])
|
||||
elif rawdata[i:i+9].lower() == '<!doctype':
|
||||
self.handle_decl(rawdata[i+2:])
|
||||
elif startswith("<!", i):
|
||||
|
@ -350,15 +347,12 @@ def parse_html_declaration(self, i):
|
|||
if rawdata[i:i+4] == '<!--':
|
||||
# this case is actually already handled in goahead()
|
||||
return self.parse_comment(i)
|
||||
elif rawdata[i:i+9] == '<![CDATA[':
|
||||
if self._support_cdata:
|
||||
j = rawdata.find(']]>', i+9)
|
||||
if j < 0:
|
||||
return -1
|
||||
self.unknown_decl(rawdata[i+3: j])
|
||||
return j + 3
|
||||
else:
|
||||
return self.parse_bogus_comment(i)
|
||||
elif rawdata[i:i+9] == '<![CDATA[' and self._support_cdata:
|
||||
j = rawdata.find(']]>', i+9)
|
||||
if j < 0:
|
||||
return -1
|
||||
self.unknown_decl(rawdata[i+3: j])
|
||||
return j + 3
|
||||
elif rawdata[i:i+9].lower() == '<!doctype':
|
||||
# find the closing >
|
||||
gtpos = rawdata.find('>', i+9)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue