diff --git a/.spell-dict b/.spell-dict index c0f0c880..f70d2bc8 100644 --- a/.spell-dict +++ b/.spell-dict @@ -108,6 +108,7 @@ refactor refactored refactors registerExtension +rescan resettable richeland RSS diff --git a/docs/changelog.md b/docs/changelog.md index 5dc7b0f8..eb2d38e1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -23,6 +23,8 @@ See the [Contributing Guide](contributing.md) for details. consisting only of `{` and some text with many trailing spaces (#1656). * Fix quadratic-time regex backtracking in hash headers when a long run of `#` characters is followed by more text on the same line. +* Fix quadratic time when a document contains many unclosed HTML comments (``). * Fix regression in `BacktickInlineProcessor` where text could be lost when opening and closing backticks did not match (#1668). * Escape the language name in the `codehilite` extension's non-Pygments output to diff --git a/markdown/htmlparser.py b/markdown/htmlparser.py index fe067e70..78c9e04f 100644 --- a/markdown/htmlparser.py +++ b/markdown/htmlparser.py @@ -158,6 +158,8 @@ def reset(self): self._cache: list[str] = [] self.cleandoc: list[str] = [] self.lineno_start_cache = [0] + # The `rawdata` and position of the last failed search for a comment close. + self._no_commentclose: tuple[str | None, int] = (None, 0) super().reset() @@ -359,8 +361,15 @@ def parse_pi(self, i: int) -> int: def parse_comment(self, i, report=True): rawdata = self.rawdata assert rawdata.startswith('