gemini-cli - 💡(How to fix) Fix [Bug] \n characters expanded to literal newlines in code replacement [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#26493Fetched 2026-05-06 06:36:13
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Timeline (top)
commented ×1labeled ×1

Root Cause

can't copy the full prompt because it contain code i don't want to share publicly.

Code Example

Python
# Expected:
content_str.split("\n\n---\n\n", 1)[1]

# Actual (broken):
content_str.split("
---
", 1)[1]
RAW_BUFFERClick to expand / collapse

What happened?

The code replacement engine incorrectly interprets the \n escape sequence as a literal carriage return within strings. This breaks the code structure and introduces syntax errors.

Example of Incorrect Output Instead of maintaining the string literal, the tool produces:

Python
# Expected:
content_str.split("\n\n---\n\n", 1)[1]

# Actual (broken):
content_str.split("
---
", 1)[1]

What did you expect to happen?

Escape sequences like \n inside string literals should be preserved as text and not rendered as actual line breaks in the output file.

Client information

can't copy the full prompt because it contain code i don't want to share publicly.

Environment

Cli Version: 0.40.1 OS: Linux Mint 21.3

Login information

using Google account with a pro subscription.

Thank for you help Regards

helldrum

extent analysis

TL;DR

The code replacement engine needs to be configured or updated to correctly handle escape sequences like \n within string literals.

Guidance

  • Verify that the code replacement engine is properly escaping special characters, especially within string literals.
  • Check the engine's documentation for any configuration options or flags related to handling escape sequences.
  • Consider using a different method to represent line breaks within string literals, such as using a different escape sequence or encoding.
  • If possible, test the code replacement engine with a minimal example to isolate the issue and confirm the expected behavior.

Example

# Test case to verify escape sequence handling
test_str = "Hello\nWorld"
print(test_str)  # Expected output: Hello\nWorld

Notes

The exact solution may depend on the specific code replacement engine being used, which is not explicitly mentioned in the issue.

Recommendation

Apply a workaround, such as using a different representation for line breaks within string literals, until the code replacement engine is updated or configured to correctly handle escape sequences.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - 💡(How to fix) Fix [Bug] \n characters expanded to literal newlines in code replacement [1 comments, 2 participants]