fix(core): preserve backslashes before newlines in unescaping logic#27002
fix(core): preserve backslashes before newlines in unescaping logic#27002cocosheng-g wants to merge 1 commit into
Conversation
|
Size Change: -207 B (0%) Total Size: 34.1 MB
ℹ️ View Unchanged
|
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 an issue where backslashes were being incorrectly stripped from file content during processing. By refining the unescaping logic to treat backslashes before newlines as literal characters rather than escape sequences, the change ensures that syntax like C-style macro line continuations remains intact. 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 modifies the unescapeStringForGeminiBug utility to prevent the removal of backslashes when they precede an actual newline character. This change addresses issue #18469, ensuring that constructs like C-style macros with line continuations are correctly preserved. The update includes modifications to the regex and switch logic in editCorrector.ts, along with updated and new test cases in editCorrector.test.ts and fileUtils.test.ts. I have no feedback to provide as there were no review comments.
Fixes #18469 by updating the unescapeStringForGeminiBug regex to exclude literal newlines. This ensures C-macros with backslash-newline continuations are not corrupted during file processing.
970aac6 to
fa79eca
Compare
Summary
Fixes issue #18469 where backslashes in C-macros were being stripped during file writes.
Details
The
unescapeStringForGeminiBugfunction ineditCorrector.tswas incorrectly matching and stripping backslashes when they preceded a literal newline character (\n). This is common in C macros for line continuation. The regex was updated to exclude\nfrom the "escapable" set while still allowing the fix for LLM-escaped characters like\\n.Risk Analysis (Low Risk)
This change is considered low risk for several reasons:
\n) from the matched set. It does not affect the handling of the literal lettern, meaning the critical fix for\\n(double-escaped newline artifacts from LLMs) is fully preserved.aggressiveUnescapeis enabled, which by default is only for non-Gemini 3 models. Modern Gemini 3 models are unaffected by default.\\\n) and the non-regression (correctly unescaping\\n,\\t, etc.). All 19 tests in the affected area pass.Related Issues
Fixes #18469
How to Validate
Run
npx vitest packages/core/src/utils/editCorrector.test.ts. Verified that\\\nis preserved and\\nis still unescaped to\n.Pre-Merge Checklist