Skip to content

Do not treat an escaped backslash at the end of a line as a hard break - #164

Merged
bobzhang merged 1 commit into
mainfrom
conformance/escaped-backslash-hard-break
Oct 2, 2026
Merged

bobzhang merged 1 commit into
mainfrom
conformance/escaped-backslash-hard-break

Conversation

@bobzhang

@bobzhang bobzhang commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Split out of #152. Found by differential fuzzing against markdown-it-py (commonmark preset).

Bug: a backslash at the end of a line is a hard line break, but not when it is itself escaped by another backslash.

Repro: a\\ followed by a newline and b rendered a\<br />b. Expected a\ followed by a soft break.

Fix: Token::newline treats the final \ as a hard break only if the run of backslashes ending the line has odd length. The run is counted with StringView::rev_iter().take_while(...).count().

Spec examples: none (the spec suite passes either way).

Tests: src/cmark_html/escaped_backslash_line_end_test.mbt.

Depends on: nothing, independent of the other PRs.

A backslash at the end of a line is a hard line break, but not when it
is escaped by another backslash: `a\\` followed by a line ending must
render as `a\` and a soft break, not as a hard break.
@bobzhang

bobzhang commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Automated review: Codex CLI (codex exec, model reasoning effort high, read-only sandbox), 1 round, on git diff against the base branch.

Verdict: signed off, no changes requested.

I sign off on the code review. No concrete correctness, regression, or code-quality problems found.

The odd/even backslash check follows CommonMark 0.31.2’s escape rules and hard-break rules. The library iterator approach is appropriate, and the tests cover the essential two-, three-, and four-backslash cases. Inspection found no regressions involving trailing spaces, CRLF, block endings, or code spans.

Codex could not run moon test in its read-only sandbox. The tests were run separately on native, js and wasm-gc and pass.

@bobzhang
bobzhang merged commit f6ba903 into main Oct 2, 2026
9 checks passed
@bobzhang
bobzhang deleted the conformance/escaped-backslash-hard-break branch October 2, 2026 01:40
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.

1 participant