From ba2cab6fc41ced55cc4630ebcc65fb6154d9dca6 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Wed, 18 Jun 2025 09:55:49 -0400 Subject: [PATCH 1/2] Ensure incomplete markup declaration in raw HTML doesn't crash parser. See Python bug report at gh-77057 for details. Until we drop support for Python < 3.13 (where this was fixed upstream), we need to avoid the unwanted error by checking for it explicitly. Fixes #1534. --- docs/changelog.md | 1 + markdown/extensions/md_in_html.py | 4 ++++ markdown/htmlparser.py | 4 ++++ tests/test_syntax/blocks/test_html_blocks.py | 7 +++++++ 4 files changed, 16 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 9f972a35..0b00d9df 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -13,6 +13,7 @@ See the [Contributing Guide](contributing.md) for details. ### Fixed +* Ensure incomplete markup declaration in raw HTML doesn't crash parser (#1534). * Fixed dropped content in `md_in_html` (#1526). * Fixed HTML handling corner case that prevented some content from not being rendered (#1528). diff --git a/markdown/extensions/md_in_html.py b/markdown/extensions/md_in_html.py index ba73c942..c8c02081 100644 --- a/markdown/extensions/md_in_html.py +++ b/markdown/extensions/md_in_html.py @@ -280,6 +280,10 @@ def parse_pi(self, i: int) -> int: def parse_html_declaration(self, i: int) -> int: if self.at_line_start() or self.intail or self.mdstack: + if self.rawdata[i:i+3] == ' int: def parse_html_declaration(self, i: int) -> int: if self.at_line_start() or self.intail: + if self.rawdata[i:i+3] == '<![

' + ) + def test_raw_cdata_code_span(self): self.assertMarkdownRenders( self.dedent( From 653890c9d9fcece6c5a4a7e601eabbd8dd733173 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Wed, 18 Jun 2025 10:07:16 -0400 Subject: [PATCH 2/2] cleanup --- markdown/extensions/md_in_html.py | 2 +- markdown/htmlparser.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/markdown/extensions/md_in_html.py b/markdown/extensions/md_in_html.py index c8c02081..5256e904 100644 --- a/markdown/extensions/md_in_html.py +++ b/markdown/extensions/md_in_html.py @@ -281,7 +281,7 @@ def parse_pi(self, i: int) -> int: def parse_html_declaration(self, i: int) -> int: if self.at_line_start() or self.intail or self.mdstack: if self.rawdata[i:i+3] == ' int: def parse_html_declaration(self, i: int) -> int: if self.at_line_start() or self.intail: if self.rawdata[i:i+3] == '