Skip to content

🐛 FIX: Don't treat U+001C-U+001F and U+0085 as whitespace in regexps - #500

Open
Harp404 wants to merge 1 commit into
executablebooks:masterfrom
Harp404:fix-whitespace-regexps
Open

Harp404 wants to merge 1 commit into
executablebooks:masterfrom
Harp404:fix-whitespace-regexps

Conversation

@Harp404

@Harp404 Harp404 commented Dec 4, 2026

Copy link
Copy Markdown

Python's regex \s also matches U+001C–U+001F and U+0085, which are not whitespace in JavaScript or CommonMark. #433 fixed this for trimming, but several regexps ported from markdown-it still use \s:

  • the HTML tag regexps in common/html_re.py and the HTML block start patterns in rules_block/html_block.py, so e.g. <b\x85c="d"> was parsed as inline HTML and <div\x1c> opened an HTML block;
  • the typographer en dash rules in rules_core/replacements.py, so a--\x85b was left alone and a\x1c-- b became an en dash.

They now use a whitespace class ([^\S\x1c-\x1f\x85]) defined in html_re.py, matching JavaScript's \s.

input markdown-it 15.0.3 before after
a <b\x85c="d"> e <p>a &lt;b\x85c=&quot;d&quot;&gt; e</p> <p>a <b\x85c="d"> e</p> same as JS
<div\x1c>\n\n*x* <p>&lt;div\x1c&gt;</p>\n<p><em>x</em></p> <div\x1c>\n<p><em>x</em></p> same as JS
a--\x85b (typographer) a–\x85b a--\x85b same as JS
a\x1c-- b (typographer) a\x1c-- b a\x1c– b same as JS

New tests in tests/test_port/test_whitespace.py cover each of the 5 characters plus controls with a space and a tab; 10 of them fail on master and all pass with this change (expected strings checked against markdown-it 15.0.3). The full suite, ruff and mypy pass.

Not included: JS $ in multiline mode also matches before U+2028/U+2029, which overlaps #469.

I used Claude Code (Opus 5.5) to help investigate and draft this change; I reproduced the bug and checked the fix myself.

Python's \s also matches U+001C-U+001F and U+0085, which are not whitespace
in JavaScript or CommonMark. The HTML tag and HTML block regexps and the
typographer en dash rules used \s where upstream markdown-it uses the
JavaScript \s, so e.g. '<b\x85c="d">' was parsed as an HTML tag and
'a--\x85b' was not turned into an en dash, unlike markdown-it.
Copilot AI balanced review requested due to automatic review settings December 4, 2026 08:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

2 participants