Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8207214

Browse files
authored
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.
1 parent 64a3c0f commit 8207214

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

‎docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the [Contributing Guide](contributing.md) for details.
1313

1414
### Fixed
1515

16+
* Ensure incomplete markup declaration in raw HTML doesn't crash parser (#1534).
1617
* Fixed dropped content in `md_in_html` (#1526).
1718
* Fixed HTML handling corner case that prevented some content from not being rendered (#1528).
1819

‎markdown/extensions/md_in_html.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ def parse_pi(self, i: int) -> int:
280280

281281
def parse_html_declaration(self, i: int) -> int:
282282
if self.at_line_start() or self.intail or self.mdstack:
283+
if self.rawdata[i:i+3] == '<![' and not self.rawdata[i:i+9] == '<![CDATA[':
284+
# We have encountered the bug in #1534 (Python bug `gh-77057`).
285+
# Provide an override until we drop support for Python < 3.13.
286+
return self.parse_bogus_comment(i)
283287
# The same override exists in `HTMLExtractor` without the check
284288
# for `mdstack`. Therefore, use parent of `HTMLExtractor` instead.
285289
return super(HTMLExtractor, self).parse_html_declaration(i)

‎markdown/htmlparser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ def parse_pi(self, i: int) -> int:
275275

276276
def parse_html_declaration(self, i: int) -> int:
277277
if self.at_line_start() or self.intail:
278+
if self.rawdata[i:i+3] == '<![' and not self.rawdata[i:i+9] == '<![CDATA[':
279+
# We have encountered the bug in #1534 (Python bug `gh-77057`).
280+
# Provide an override until we drop support for Python < 3.13.
281+
return self.parse_bogus_comment(i)
278282
return super().parse_html_declaration(i)
279283
# This is not the beginning of a raw block so treat as plain data
280284
# and avoid consuming any tags which may follow (see #1066).

‎tests/test_syntax/blocks/test_html_blocks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,13 @@ def test_raw_cdata_indented(self):
12751275
)
12761276
)
12771277

1278+
def test_not_actually_cdata(self):
1279+
# Ensure bug reported in #1534 is avoided.
1280+
self.assertMarkdownRenders(
1281+
'<![',
1282+
'<p>&lt;![</p>'
1283+
)
1284+
12781285
def test_raw_cdata_code_span(self):
12791286
self.assertMarkdownRenders(
12801287
self.dedent(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /