From 43f12ba95b3a7036d8a9bd82865d680bb955bfc0 Mon Sep 17 00:00:00 2001 From: Jah-yee <166608075+Jah-yee@users.noreply.github.com> Date: Fri, 22 May 2026 23:43:14 +0800 Subject: [PATCH] fix: prevent mixed =/- chars in Setext-style headings The regex [=-]+ incorrectly matches mixed runs like '=-' or '-=' which are not valid Setext headers (only = or - alone are valid). Fix using (?:[=]+|[-]+) to match only homogeneous runs. Fixes issue #1604 --- markdown/blockprocessors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 3ed4cf07f..71d8854eb 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -494,7 +494,7 @@ class SetextHeaderProcessor(BlockProcessor): """ Process Setext-style Headers. """ # Detect Setext-style header. Must be first 2 lines of block. - RE = re.compile(r'^.*?\n[=-]+[ ]*(\n|$)', re.MULTILINE) + RE = re.compile(r'^.*?\n(?:[=]+|[-]+)[ ]*(\n|$)', re.MULTILINE) def test(self, parent: etree.Element, block: str) -> bool: return bool(self.RE.match(block))