close
Skip to content

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

Open
Jah-yee wants to merge 2 commits 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 2 commits 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
@waylan
Copy link
Copy Markdown
Member

waylan commented May 23, 2026

Thanks for your submission. There are two failing tests that need addressed.

  1. The lint (flake8) test is failing because you missed adding a blank line after your third test.
  2. The changelog-enforcer test is failing because you did not add an entry to the changelog.

Please do not close this issue and open a new one. Also, do not replace your commit and force-push. Instead, add additional commits to this issue to make the changes while preserving the existing commits you already made. Please review the Contributing Guide for more information. If anything is still unclear, please feel free to ask.

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

2 participants