Replace U+0000 with U+FFFD on input per CommonMark §2.3#263
Merged
Conversation
CommonMark §2.3 ("Insecure characters") requires that literal U+0000
code points in source be replaced with U+FFFD. Marko's entity-reference
path already honours this for � / �, but literal NULs in the
input were passed straight through to text, code spans, and code blocks.
Add the substitution to _preprocess_text so that all parser/renderer
paths see a sanitised buffer. Add regression tests covering NUL in
plain text, code spans, and fenced code blocks.
frostming
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CommonMark §2.3 requires literal
U+0000characters to be replaced withU+FFFD.Marko already does this for entity references like
�and�, but literal NUL characters in the input are currently preserved in the rendered HTML.Reproduction
The same issue also happens inside fenced code blocks.
Fix
Apply the
\x00to�substitution in_preprocess_text()after line-ending normalization.This makes all parser and renderer paths see the same sanitized input, and keeps the behavior consistent with the existing entity-reference handling.
Tests
Added regression tests for:
All existing tests still pass.