diff --git a/docs/changelog.md b/docs/changelog.md index 6db0b5c0..c51967e1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -17,6 +17,7 @@ See the [Contributing Guide](contributing.md) for details. * Ensure nested elements inside inline comments are properly unescaped (#1571). * Make the docs build successfully with mkdocstrings-python 2.0 (#1575). * Fix infinite loop when multiple bogus or unclosed HTML comments appear in input (#1578). +* Fix another infinite loop when handling bad comments (#1586). ## [3.10.0] - 2025-11-03 diff --git a/markdown/htmlparser.py b/markdown/htmlparser.py index 697f84f2..74dbe25a 100644 --- a/markdown/htmlparser.py +++ b/markdown/htmlparser.py @@ -126,6 +126,7 @@ def reset(self): self.cleandoc: list[str] = [] self.lineno_start_cache = [0] self.override_comment_start = 0 + self.override_comment_update = False super().reset() @@ -275,11 +276,11 @@ def handle_entityref(self, name: str): def handle_comment(self, data: str): # Check if the comment is unclosed, if so, we need to override position - i = self.line_offset + self.offset + len(data) + 4 - if self.rawdata[i:i + 3] != '-->': + j = len(self.rawdata) - len(data) + i = j - 2 + if self.rawdata[i:j] == ''.format(data), is_block=True) @@ -309,21 +310,19 @@ def parse_pi(self, i: int) -> int: self.handle_data(' int: if self.at_line_start() or self.intail: diff --git a/tests/test_syntax/blocks/test_html_blocks.py b/tests/test_syntax/blocks/test_html_blocks.py index 3251d0fa..406de997 100644 --- a/tests/test_syntax/blocks/test_html_blocks.py +++ b/tests/test_syntax/blocks/test_html_blocks.py @@ -1698,3 +1698,11 @@ def test_multiple_unclosed_comments_no_hang(self): '