Skip to content

fix(core): preserve escape sequences in string literals for modern models#28299

Merged
DavidAPierce merged 2 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_496211054
Jul 6, 2026
Merged

fix(core): preserve escape sequences in string literals for modern models#28299
DavidAPierce merged 2 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_496211054

Conversation

@luisfelipe-alt

@luisfelipe-alt luisfelipe-alt commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes the newline-in-string bug (b-496211054) where valid escape sequences (like \n or \t) inside string literals were being converted to literal newlines when writing files.

Details

The fix disables aggressive unescaping for all modern models (Gemini 2.x, Gemini 3.x, and Custom models) by resolving the model first and checking their families in packages/core/src/tools/write-file.ts.

To support dynamic model configurations (e.g., via getExperimentalDynamicModelConfiguration), the config context is passed to resolveModel, isGemini3Model, and isCustomModel.

Comprehensive unit tests have been added/updated:

  • packages/core/src/utils/editCorrector.test.ts: Verifies that escape sequences are preserved when aggressiveUnescape is false.
  • packages/core/src/tools/write-file.test.ts: Updated mock model to gemini-1.5-flash to ensure correct test coverage and alignment with the new unescaping logic.

Related Issues

How to Validate

  1. Run unit tests:

    npm test -w @google/gemini-cli-core -- src/utils/editCorrector.test.ts src/tools/write-file.test.ts

    Expected output: All tests pass successfully.

  2. Run linter:

    npm run lint

    Expected output: 0 warnings and 0 errors.

  3. Run typecheck:

    npm run typecheck

    Expected output: Successful compilation with no TypeScript errors.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@luisfelipe-alt luisfelipe-alt requested review from a team as code owners July 6, 2026 05:27
@github-actions github-actions Bot added the size/s A small PR label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 34
  • Additions: +30
  • Deletions: -4
  • Files changed: 3

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug where valid escape sequences within string literals were incorrectly converted to literal characters during file write operations. By updating the model resolution logic, the system now correctly identifies modern model families and disables aggressive unescaping for them, preventing unwanted modifications to code content.

Highlights

  • Preservation of Escape Sequences: Modified the file writing logic to disable aggressive unescaping for modern model families, ensuring that escape sequences like \n and \t are preserved in string literals.
  • Model Resolution Update: Updated the logic in write-file.ts to resolve the active model and check against Gemini 2.x, 3.x, and custom model families before determining the unescaping strategy.
  • Regression Testing: Added a new unit test in editCorrector.test.ts to verify that escape sequences remain intact when aggressive unescaping is disabled.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the unescaping logic in write-file.ts to disable aggressive unescaping for Gemini 2, Gemini 3, and custom models, and adds a unit test to verify this behavior. The review feedback correctly points out that the config context must be passed to resolveModel, isGemini3Model, and isCustomModel to prevent bypassing dynamic model configurations.

Comment thread packages/core/src/tools/write-file.ts Outdated
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the write-file tool to resolve the active model using resolveModel and disables aggressive unescaping for Gemini 2, Gemini 3, and custom models. It also updates the corresponding unit tests to use gemini-1.5-flash as the mock model and adds a test case to verify that newlines inside string literals are preserved when aggressive unescaping is disabled. There are no review comments, so I have no feedback to provide.

@DavidAPierce DavidAPierce added this pull request to the merge queue Jul 6, 2026
Merged via the queue into google-gemini:main with commit 15a9429 Jul 6, 2026
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s A small PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants