Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more edge cases and tests
  • Loading branch information
Privat33r-dev committed Apr 6, 2024
commit 9147ff64f87e8c268300be493889ab2b4aefc77f
4 changes: 2 additions & 2 deletions Lib/_markupbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def parse_declaration(self, i):
# A simple, practical version could look like: ((name|stringlit) S*) + '>'
n = len(rawdata)
if rawdata[j:j+2] == '--': #comment
# Locate --.*-- as the body of the comment
# Locate the body of the comment.
return self.parse_comment(i)
elif rawdata[j] == '[': #marked section
# Locate [statusWord [...arbitrary SGML...]] as the body of the marked section
Expand Down Expand Up @@ -166,7 +166,7 @@ def parse_comment(self, i, report=1):
rawdata = self.rawdata
if rawdata[i:i+4] != '<!--':
raise AssertionError('unexpected call to parse_comment()')
match = _commentclose.search(rawdata, i+4)
match = _commentclose.search(rawdata, i+2)
if not match:
return -1
if report:
Expand Down
12 changes: 10 additions & 2 deletions Lib/test/test_htmlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,22 @@ def test_comments(self):
'<!---->'
'<!----I have many hyphens---->'
'<!-- I have a > in the middle -->'
'<!-- and I have -- in the middle! -->')
'<!-- and I have -- in the middle! -->'
'<!--->'
'<!-->'
'<!--<!--->'
'<!--incorrectly-closed-comment--!>')
expected = [('comment', " I'm a valid comment "),
('comment', 'me too!'),
('comment', '--'),
('comment', ''),
('comment', '--I have many hyphens--'),
('comment', ' I have a > in the middle '),
('comment', ' and I have -- in the middle! ')]
('comment', ' and I have -- in the middle! '),
('comment', ''),
('comment', ''),
('comment', '<!-'),
('comment', 'incorrectly-closed-comment')]
self._run_check(html, expected)

def test_condcoms(self):
Expand Down