Skip to content

gh-154711: Strip comments after escaped quotes in f-string and t-string debug text - #154914

Open
ArneshBanerjee wants to merge 1 commit into
python:mainfrom
ArneshBanerjee:fix-gh-154711-fstring-comment-leak
Open

gh-154711: Strip comments after escaped quotes in f-string and t-string debug text#154914
ArneshBanerjee wants to merge 1 commit into
python:mainfrom
ArneshBanerjee:fix-gh-154711-fstring-comment-leak

Conversation

@ArneshBanerjee

@ArneshBanerjee ArneshBanerjee commented Jul 30, 2026

Copy link
Copy Markdown

When a replacement field ended with a string that had an escaped quote and was followed by a comment, the comment leaked into the output. It showed up in debug f-string results and in t-string metadata.

The comment detection loop in _PyLexer_set_ftstring_expr skips escaped characters, but the comment stripping loop did not. So an escaped quote left the scanner thinking it was still inside a string, and the comment was never removed.

This makes the stripping loop skip escaped characters the same way the detection loop does, so the comment is removed as expected. Tests are added for f-strings and t-strings.

Fixes #154711

…t-string debug text

When a replacement field ended with a string that had an escaped quote and
was followed by a comment, the comment leaked into the output. It showed up
in debug f-string results and in t-string metadata.

The comment detection loop in _PyLexer_set_ftstring_expr skips escaped
characters, but the comment stripping loop did not. So an escaped quote left
the scanner thinking it was still inside a string, and the comment was never
removed.

This makes the stripping loop skip escaped characters the same way the
detection loop does, so the comment is removed as expected. Tests are added
for f-strings and t-strings.
@python-cla-bot

python-cla-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Escaped quotes cause source comments to leak into debug f-string output and t-string metadata

1 participant