Skip to content

Commit 9147ff6

Browse files
committed
Add more edge cases and tests
1 parent 4536d8b commit 9147ff6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Lib/_markupbase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def parse_declaration(self, i):
8181
# A simple, practical version could look like: ((name|stringlit) S*) + '>'
8282
n = len(rawdata)
8383
if rawdata[j:j+2] == '--': #comment
84-
# Locate --.*-- as the body of the comment
84+
# Locate the body of the comment.
8585
return self.parse_comment(i)
8686
elif rawdata[j] == '[': #marked section
8787
# Locate [statusWord [...arbitrary SGML...]] as the body of the marked section
@@ -166,7 +166,7 @@ def parse_comment(self, i, report=1):
166166
rawdata = self.rawdata
167167
if rawdata[i:i+4] != '<!--':
168168
raise AssertionError('unexpected call to parse_comment()')
169-
match = _commentclose.search(rawdata, i+4)
169+
match = _commentclose.search(rawdata, i+2)
170170
if not match:
171171
return -1
172172
if report:

Lib/test/test_htmlparser.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,22 @@ def test_comments(self):
324324
'<!---->'
325325
'<!----I have many hyphens---->'
326326
'<!-- I have a > in the middle -->'
327-
'<!-- and I have -- in the middle! -->')
327+
'<!-- and I have -- in the middle! -->'
328+
'<!--->'
329+
'<!-->'
330+
'<!--<!--->'
331+
'<!--incorrectly-closed-comment--!>')
328332
expected = [('comment', " I'm a valid comment "),
329333
('comment', 'me too!'),
330334
('comment', '--'),
331335
('comment', ''),
332336
('comment', '--I have many hyphens--'),
333337
('comment', ' I have a > in the middle '),
334-
('comment', ' and I have -- in the middle! ')]
338+
('comment', ' and I have -- in the middle! '),
339+
('comment', ''),
340+
('comment', ''),
341+
('comment', '<!-'),
342+
('comment', 'incorrectly-closed-comment')]
335343
self._run_check(html, expected)
336344

337345
def test_condcoms(self):

0 commit comments

Comments
 (0)