Repository navigation
Normalize lone CR to LF in str source for exec(), eval() and -c - #9762
Closed
youknowone with Copilot wants to merge 2 commits into
Closed
youknowone with Copilot wants to merge 2 commits into
youknowone with Copilot wants to merge 2 commits into
Conversation
Contributor
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix lone carriage return in string literals for exec and eval
Normalize lone CR to LF in str source for Nov 9, 2026
exec(), eval() and -c
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.
When source is passed to
exec()oreval()as astr, or via-c, a lone\rinside a string literal stays'\r'. CPython reads it as'\n', as it does for CRLF. The language reference says line-ending sequences are replaced by LF "even inside string literals". Docstrings with CR-only breaks also went uncleaned, andexec(text)differed fromexec(text.encode()).These paths skip the source decoder and reach
compile_with_syntax_warning_handler, which only replaced"\r\n". The parser copies literal text from the source as is, so an unnormalized CR ended up in the value.crates/compiler/src/lib.rs:compile_with_syntax_warning_handlernow also replaces any remaining\rwith\n, after the CRLF replacement.#[cfg(windows)]\r\nreplacement near line 2082 is untouched.exec(),eval()and-ckeep a lone CR in string literals when the source is astr#9761