Skip to content

fix: prevent mixed =/- chars in Setext-style headings (+tests)#1606

Open
Jah-yee wants to merge 1 commit into
Python-Markdown:masterfrom
Jah-yee:fix/setext-heading-regex
Open

fix: prevent mixed =/- chars in Setext-style headings (+tests)#1606
Jah-yee wants to merge 1 commit into
Python-Markdown:masterfrom
Jah-yee:fix/setext-heading-regex

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented May 22, 2026

Summary

This PR fixes issue #1604 - mixed =/- characters in Setext-style headers were incorrectly matched.

Changes

  • markdown/blockprocessors.py: Changed regex from [=-]+ to (?:[=]+|[-]+) to match only homogeneous runs
  • tests/test_syntax/blocks/test_headers.py: Added 3 test cases for mixed-char rejection

Tests Added

  • test_setext_mixed_chars_not_h1: =- should not form an H1
  • test_setext_mixed_chars_not_h2: -= should not form an H2
  • test_setext_mixed_multiple_chars: Mixed runs are not valid headers

Closes #1604

@Jah-yee
Copy link
Copy Markdown
Author

Jah-yee commented May 22, 2026

Added 3 test cases in tests/test_syntax/blocks/test_headers.py covering mixed-char rejection (test_setext_mixed_chars_not_h1, test_setext_mixed_chars_not_h2, test_setext_mixed_multiple_chars). All tests pass. The fix is ready for review!

@Jah-yee Jah-yee force-pushed the fix/setext-heading-regex branch from e3f98c7 to be69b20 Compare May 23, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect parsing of Setext-style headings

1 participant