Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ Patches and suggestions
- Ville Skyttä
- Hugo van Kemenade
- Mark Vasilkov

- Muneeb Sheikh
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Features:

Bug fixes:

* Detect declared encodings after short comments whose terminators overlap
the comment opener. (#427)

* The sanitizer now permits ``<summary>`` tags. It used to allow ``<details>``
already. (#423)

Expand Down
3 changes: 2 additions & 1 deletion html5lib/_inputstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,8 @@ def getEncoding(self):
return self.encoding

def handleComment(self):
"""Skip over comments"""
"""Skip over comments, including terminators overlapping the opener."""
self.data.position -= 2
return self.data.jumpTo(b"-->")

def handleMeta(self):
Expand Down
16 changes: 16 additions & 0 deletions html5lib/tests/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,19 @@ def test_chardet():
encoding = _inputstream.HTMLInputStream(fp.read()).charEncoding
assert encoding[0].name == "big5"
# pylint:enable=wrong-import-position


@pytest.mark.parametrize("comment", [b"<!-->", b"<!--->", b"<!---->", b"<!--normal-->"])
def test_prescan_short_comments(comment):
data = comment + b"<meta charset=iso-8859-2>"
encoding = _inputstream.EncodingParser(data).getEncoding()
assert encoding is not None
assert encoding.name == "iso-8859-2"
stream = _inputstream.HTMLBinaryInputStream(data, useChardet=False)
assert stream.charEncoding[0].name == "iso-8859-2"


def test_prescan_ignores_meta_inside_comment():
data = b"<!--<meta charset=utf-8>--><meta charset=iso-8859-2>"
encoding = _inputstream.EncodingParser(data).getEncoding()
assert encoding.name == "iso-8859-2"