fix(core): preserve escape sequences in string literals for modern models#28299
Conversation
|
📊 PR Size: size/S
|
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
|
/gemini review |
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
e56f8ee to
d8e7a13
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
Summary
This PR fixes the newline-in-string bug (b-496211054) where valid escape sequences (like
\nor\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 toresolveModel,isGemini3Model, andisCustomModel.Comprehensive unit tests have been added/updated:
packages/core/src/utils/editCorrector.test.ts: Verifies that escape sequences are preserved whenaggressiveUnescapeisfalse.packages/core/src/tools/write-file.test.ts: Updated mock model togemini-1.5-flashto ensure correct test coverage and alignment with the new unescaping logic.Related Issues
How to Validate
Run unit tests:
npm test -w @google/gemini-cli-core -- src/utils/editCorrector.test.ts src/tools/write-file.test.tsExpected output: All tests pass successfully.
Run linter:
Expected output: 0 warnings and 0 errors.
Run typecheck:
Expected output: Successful compilation with no TypeScript errors.
Pre-Merge Checklist