René's URL Explorer Experiment


Title: Escaped quotes cause source comments to leak into debug f-string output and t-string metadata · Issue #154711 · python/cpython · GitHub

Open Graph Title: Escaped quotes cause source comments to leak into debug f-string output and t-string metadata · Issue #154711 · python/cpython

X Title: Escaped quotes cause source comments to leak into debug f-string output and t-string metadata · Issue #154711 · python/cpython

Description: Bug report Bug description: When an f-string or t-string replacement expression contains a backslash-escaped quote, a following source comment can be copied into runtime output or t-string metadata. Observed effects: A debug f-string inc...

Open Graph Description: Bug report Bug description: When an f-string or t-string replacement expression contains a backslash-escaped quote, a following source comment can be copied into runtime output or t-string metadata...

X Description: Bug report Bug description: When an f-string or t-string replacement expression contains a backslash-escaped quote, a following source comment can be copied into runtime output or t-string metadata...

Opengraph URL: https://github.com/python/cpython/issues/154711

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Escaped quotes cause source comments to leak into debug f-string output and t-string metadata","articleBody":"# Bug report\n\n### Bug description:\n\nWhen an f-string or t-string replacement expression contains a backslash-escaped quote, a following source comment can be copied into runtime output or t-string metadata.\n\nObserved effects:\n\n- A debug f-string includes the source comment in the resulting str.\n- A debug t-string includes the comment in Template.strings.\n- A debug t-string includes both the debug = and the comment inInterpolation.expression.\n- A non-debug t-string also retains the comment inInterpolation.expression.\n\nThe replacement expression itself evaluates to the correct value. The problemappears to be in reconstruction of the replacement-field source text.\n\n## Reproducer\n```python\nf_result = f\"{'\\'' = # c\n}\"\n\nt_debug = t\"{'a\\'b' = # c\n}\"\nt_plain = t\"{'a\\'b' # c\n}\"\n\nprint(\"debug f-string result:\", repr(f_result))\nprint(\"\\ndebug t-string strings:\", repr(t_debug.strings))\nprint(\"\\ndebug t-string expression:\", repr(t_debug.interpolations[0].expression))\nprint(\"\\nnon-debug t-string expression:\", repr(t_plain.interpolations[0].expression))\n```\n\n## Actual behavior\n\nOn CPython main commit b86a41c, the output contains the source text # c in all four observed values.\n```text\ndebug f-string result: '\\'\\\\\\'\\' = # c\\n\"\\'\"'\n\ndebug t-string strings: (\"'a\\\\'b' = # c\\n\", '')\n\ndebug t-string expression: \"'a\\\\'b' = # c\"\n\nnon-debug t-string expression: \"'a\\\\'b' # c\"\n```\n\n## Possible cause\n\nThe behavior appears to be caused by inconsistent escaped-character handling between two scans in `_PyLexer_set_ftstring_expr() ` in `Parser/lexer/string.c`.\n\nThe initial scan that detects a comment outside a string literal explicitly skips a backslash and the character following it:\n```c\nif (ch == '\\\\') {\n    i++;\n    continue;\n}\n```\nHowever, after a comment has been detected, the subsequent reconstruction pass that removes comments appears not to perform the equivalent skip. It changes `in_string` whenever it encounters a quote:\n```c\nif (ch == '\"' || ch == '\\'') {\n    if (!in_string) {\n        in_string = 1;\n        quote_char = ch;\n    }\n    else if (ch == quote_char) {\n        in_string = 0;\n    }\n}\nelse if (ch == '#' && !in_string) {\n    /* skip the comment */\n}\n```\nFor:\n```python\n'a\\'b' = # c\n```\nthe second pass may interpret the escaped quote as the end of the string and the real closing quote as the beginning of another string:\n```text\n'       begin string\n\\       treated as an ordinary character\n'       incorrectly treated as end of string\nb\n'       incorrectly treated as beginning of another string\n#       incorrectly considered to be inside a string\n```\nConsequently, the # is not recognized by the comment-removal branch and the comment is copied into the reconstructed text.\nThis also explains why the same input pattern affects both f-strings and t-strings: both use the same replacement-expression reconstruction logic.\nThis is a proposed root cause based on the observed behavior and source review, not a confirmed diagnosis.\n\n\n### CPython versions tested on:\n\nCPython main branch, 3.16\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154914\n* gh-158220\n* gh-158310\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/kid-lxy","@type":"Person","name":"kid-lxy"},"datePublished":"2026-07-26T07:01:48Z","url":"https://github.com/python/cpython/issues/154711"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:01f1f52c-fb19-a780-f354-1572968aec36
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8C88:CE438:125C2BD:18824E2:6B01FE9D
html-safe-nonce3f4f44cef20f7e2101c40eede0fbe8709eb17be36ca668637a823a046c55c2d3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Qzg4OkNFNDM4OjEyNUMyQkQ6MTg4MjRFMjo2QjAxRkU5RCIsInZpc2l0b3JfaWQiOiI2ODY0ODUzODYyNTk2MDgzMzU3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac58d99edfad01e9af70be393ddb0e161bd2e322a069000b00bad81e2a7591d262
hovercard-subject-tagissue:4979512543
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/154711/issue_layout
twitter:imagehttps://opengraph.githubassets.com/13112e19c1c953ebb9f2a6e9be3a574f20afad6457bbd1854804da32ec092c19/python/cpython/issues/154711
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/13112e19c1c953ebb9f2a6e9be3a574f20afad6457bbd1854804da32ec092c19/python/cpython/issues/154711
og:image:altBug report Bug description: When an f-string or t-string replacement expression contains a backslash-escaped quote, a following source comment can be copied into runtime output or t-string metadata...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamekid-lxy
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/154711#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F154711
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F154711
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/154711
Reloadhttps://github.com/python/cpython/issues/154711
Reloadhttps://github.com/python/cpython/issues/154711
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/154711
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/154711
Escaped quotes cause source comments to leak into debug f-string output and t-string metadatahttps://github.com/python/cpython/issues/154711#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-parserhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-parser%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/kid-lxy
kid-lxyhttps://github.com/kid-lxy
on Jul 26, 2026https://github.com/python/cpython/issues/154711#issue-4979512543
b86a41chttps://github.com/python/cpython/commit/b86a41cbf631c959d274ad6180cf0a0ac6f6e180
[3.13] gh-154711: Strip comments after escaped quotes in f-string debug text #154914https://github.com/python/cpython/pull/154914
gh-154711: Add tests for comments after escaped quotes in f-strings and t-strings #158220https://github.com/python/cpython/pull/158220
[3.13] gh-154711: Strip comments after escaped quotes in f-string debug text #158310https://github.com/python/cpython/pull/158310
kid-lxyhttps://github.com/kid-lxy
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Jul 26, 2026https://github.com/python/cpython/issues/154711#event-28493342100
picnixzhttps://github.com/picnixz
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Jul 26, 2026https://github.com/python/cpython/issues/154711#event-28493709078
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Jul 26, 2026https://github.com/python/cpython/issues/154711#issuecomment-5082542538
picnixzhttps://github.com/picnixz
pendingThe issue will be closed if no feedback is providedhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22pending%22
topic-parserhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-parser%22
pendingThe issue will be closed if no feedback is providedhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22pending%22
on Jul 26, 2026https://github.com/python/cpython/issues/154711#event-28493735120
https://github.com/tekinertekin
tekinertekinhttps://github.com/tekinertekin
on Jul 29, 2026https://github.com/python/cpython/issues/154711#issuecomment-5120315069
@picnixzhttps://github.com/picnixz
https://github.com/dqqFA8995
dqqFA8995https://github.com/dqqFA8995
on Jul 29, 2026https://github.com/python/cpython/issues/154711#issuecomment-5120468006
…https://github.com/python/cpython/issues/154711
python/cpython#154711https://github.com/python/cpython/issues/154711
#154711 (comment)https://github.com/python/cpython/issues/154711#issuecomment-5120315069
@picnixzhttps://github.com/picnixz
https://github.com/picnixzhttps://github.com/picnixz
#154711https://github.com/python/cpython/issues/154711
https://github.com/notifications/unsubscribe-auth/CI4YCMAEADS2BXU3EQPQO735HINONAVCNFSNUABEKJSXA33TNF2G64TZHM4DCNJZHA4TMMJ3JFZXG5LFHM2DSNZZGUYTENJUGOQXMAQhttps://github.com/notifications/unsubscribe-auth/CI4YCMAEADS2BXU3EQPQO735HINONAVCNFSNUABEKJSXA33TNF2G64TZHM4DCNJZHA4TMMJ3JFZXG5LFHM2DSNZZGUYTENJUGOQXMAQ
https://github.com/notifications/mobile/ios/CI4YCMH6YATEB5S65EFOJOT5HINONA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJSGAZTCNJQGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQhttps://github.com/notifications/mobile/ios/CI4YCMH6YATEB5S65EFOJOT5HINONA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJSGAZTCNJQGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ
https://github.com/notifications/mobile/android/CI4YCMHQ3NSHLJU3PNLJFET5HINONA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJSGAZTCNJQGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQhttps://github.com/notifications/mobile/android/CI4YCMHQ3NSHLJU3PNLJFET5HINONA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJSGAZTCNJQGY42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ
ArneshBanerjeehttps://github.com/ArneshBanerjee
on Sep 26, 2026https://github.com/python/cpython/issues/154711#event-31881317801
[3.13] pythongh-154711: Strip comments after escaped quotes in f-stri…https://github.com/ArneshBanerjee/cpython/commit/2877218adf4fd29bbfb8bae2b9617483de56ffbb
pythongh-154711https://github.com/python/cpython/issues/154711
2877218https://github.com/ArneshBanerjee/cpython/commit/2877218adf4fd29bbfb8bae2b9617483de56ffbb
pablogsalhttps://github.com/pablogsal
on Sep 29, 2026https://github.com/python/cpython/issues/154711#event-32119976186
[3.13] gh-154711: Strip comments after escaped quotes in f-string deb…https://github.com/python/cpython/commit/4192eadc82226f55f0fd1e12ab27aeb5c51631fc
gh-154711https://github.com/python/cpython/issues/154711
4192eadhttps://github.com/python/cpython/commit/4192eadc82226f55f0fd1e12ab27aeb5c51631fc
ArneshBanerjeehttps://github.com/ArneshBanerjee
on Oct 9, 2026https://github.com/python/cpython/issues/154711#event-32836557501
Merge branch 'main' into pythongh-154711-tests-mainhttps://github.com/ArneshBanerjee/cpython/commit/5ee3d05a4126c53e9b0b40bb4a3136e5bc559277
pythongh-154711https://github.com/python/cpython/issues/154711
5ee3d05https://github.com/ArneshBanerjee/cpython/commit/5ee3d05a4126c53e9b0b40bb4a3136e5bc559277
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/154711#event-33592122204
github-project-automationhttps://github.com/apps/github-project-automation
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/154711
github-project-automationhttps://github.com/apps/github-project-automation
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/154711
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/154711#event-33592173286
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/154711
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/154711
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-parserhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-parser%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.