Skip to content

Normalize lone CR to LF in str source for exec(), eval() and -c - #9762

Closed
youknowone with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-cr-in-string-literals
Closed

youknowone with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-cr-in-string-literals

Conversation

Copilot AI commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

When source is passed to exec() or eval() as a str, or via -c, a lone \r inside 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, and exec(text) differed from exec(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_handler now also replaces any remaining \r with \n, after the CRLF replacement.
eval('"""a\rb"""')   # before: 'a\rb'   after: 'a\nb'
  • The #[cfg(windows)] \r\n replacement near line 2082 is untouched.
  • No regression test is added.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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 exec(), eval() and -c Nov 9, 2026
Copilot AI requested a review from youknowone November 9, 2026 12:26
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.

exec(), eval() and -c keep a lone CR in string literals when the source is a str

2 participants