Skip to content

fix(core): resolve Windows line ending and path separation bugs across CLI #21068

Merged
ruomengz merged 5 commits intogoogle-gemini:mainfrom
muhammadusman586:fix/windows-line-ending-path-separation-bugs
Mar 9, 2026
Merged

fix(core): resolve Windows line ending and path separation bugs across CLI #21068
ruomengz merged 5 commits intogoogle-gemini:mainfrom
muhammadusman586:fix/windows-line-ending-path-separation-bugs

Conversation

@muhammadusman586
Copy link
Copy Markdown
Contributor

@muhammadusman586 muhammadusman586 commented Mar 4, 2026

Summary for #20967

Fixes Windows cross-platform compatibility bugs where \r\n (CRLF) line endings
caused rendering artifacts and incorrect line counting, and where manual path
splitting by / broke filename extraction on Windows (which uses \).

Details

Root Cause:

  1. Line Endings: Several files used .split('\n') to split text into lines.
    On Windows, line endings are \r\n, so splitting by \n alone leaves a
    trailing \r on each line, causing rendering artifacts in DiffRenderer and
    CodeColorizer, and incorrect line counts in fileUtils.ts.
  2. Path Separation: A test file used filePath.split('/').pop() to extract
    filenames. On Windows, paths use \ as the separator, so this fails to
    extract the correct filename.

Fix:

  1. Replaced .split('\n') with .split(/\r?\n/) in 4 locations across 3 files.
    The regex handles both Unix (\n) and Windows (\r\n) line endings.
  2. Replaced filePath.split('/').pop() with path.basename(filePath) which is
    the idiomatic, platform-aware Node.js API for extracting filenames.

Impact: The CLI now correctly handles Windows line endings and paths in diff
rendering, code syntax highlighting, file content processing, and tests.

Files Changed

File Change
packages/cli/src/ui/components/messages/DiffRenderer.tsx .split('\n').split(/\r?\n/)
packages/cli/src/ui/utils/CodeColorizer.tsx .split('\n').split(/\r?\n/) (2 locations)
packages/core/src/utils/fileUtils.ts .split('\n').split(/\r?\n/)
packages/core/src/tools/read-many-files.test.ts filePath.split('/').pop()path.basename(filePath)

Related Issues

Fixes #20967

How to Validate

  1. Line ending fix: Open a file with Windows CRLF line endings (\r\n) and
    verify:
    • Diff rendering in DiffRenderer shows clean output without trailing \r
      characters
    • Code syntax highlighting in CodeColorizer renders correctly
    • File line counting in fileUtils.ts returns accurate counts
  2. Path separation fix: Run read-many-files tests on Windows — filename
    extraction should work correctly with backslash paths
  3. Regression: Run
    npm test -w @google/gemini-cli-core -- src/tools/read-many-files.test.ts
    all 31 tests pass

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed) - N/A
  • Added/updated tests (if needed) - N/A (existing tests cover behavior; fix
    is in test file itself)
  • Noted breaking changes (if any) - N/A (bug fix only)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@muhammadusman586 muhammadusman586 requested a review from a team as a code owner March 4, 2026 06:40
@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 significantly enhances the CLI's cross-platform compatibility, particularly for Windows environments. It resolves critical bugs related to how the application processes line endings and path separators, ensuring consistent and correct behavior in diff rendering, code highlighting, and file utility operations across different operating systems.

Highlights

  • Windows Line Endings: Updated string splitting logic from ".split('\n')" to ".split(/\r?\n/)" in DiffRenderer.tsx, CodeColorizer.tsx, and fileUtils.ts to correctly handle both Unix (\n) and Windows (\r\n) line endings, resolving rendering artifacts and incorrect line counts.
  • Path Separation: Replaced manual path splitting "filePath.split('/').pop()" with the platform-aware "path.basename(filePath)" in read-many-files.test.ts to ensure correct filename extraction on Windows, which uses \ as a path separator.
Changelog
  • packages/cli/src/ui/components/messages/DiffRenderer.tsx
    • Updated line splitting to use a regex /\r?\n/ for robust handling of Windows and Unix line endings.
  • packages/cli/src/ui/utils/CodeColorizer.tsx
    • Modified line splitting in two locations to use /\r?\n/ for accurate code highlighting regardless of line ending type.
  • packages/core/src/tools/read-many-files.test.ts
    • Replaced a manual path splitting approach with path.basename() to correctly extract filenames in a platform-agnostic manner.
  • packages/core/src/utils/fileUtils.ts
    • Adjusted line splitting logic to /\r?\n/ for accurate file content processing and line counting.
    • Removed an unnecessary eslint-disable comment.
Activity
  • Addressed Windows cross-platform compatibility issues, specifically fixing bugs related to CRLF line endings and backslash path separators.
  • Provided detailed validation steps for verifying the line ending and path separation fixes, including specific commands to run.
  • Included a comprehensive pre-merge checklist, confirming validation on MacOS, Windows, and Linux across various execution methods.
  • Fixed issue Resolve Windows line ending and path separation bugs across CLI components #20967.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Copy Markdown
Contributor

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

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 correctly addresses cross-platform compatibility issues on Windows by replacing platform-specific line splitting and path manipulation with platform-agnostic methods. The use of split(/\r?\n/) for line endings and path.basename() for extracting filenames is appropriate and resolves the described bugs. I have one concern regarding the removal of an ESLint disable comment, which could potentially cause CI failures.

@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Mar 4, 2026
@muhammadusman586 muhammadusman586 changed the title fix: resolve Windows line ending and path separation bugs across CLI fix(core): resolve Windows line ending and path separation bugs across CLI Mar 4, 2026
@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Mar 4, 2026
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.

Can we remove this?

Copy link
Copy Markdown
Contributor Author

@muhammadusman586 muhammadusman586 Mar 5, 2026

Choose a reason for hiding this comment

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

Yes remove it, it was added by mistake.

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.

Looks like this is still not removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done! The .claude/worktrees/nervous-sutherland folder has been removed. Sorry for the delay on this!

@muhammadusman586 muhammadusman586 force-pushed the fix/windows-line-ending-path-separation-bugs branch from 456dfd4 to 67d0675 Compare March 7, 2026 05:10
@ruomengz ruomengz added this pull request to the merge queue Mar 9, 2026
@ruomengz
Copy link
Copy Markdown
Contributor

ruomengz commented Mar 9, 2026

Thanks for fixing!

Merged via the queue into google-gemini:main with commit f88488d Mar 9, 2026
27 checks passed
kunal-10-cloud pushed a commit to kunal-10-cloud/gemini-cli that referenced this pull request Mar 12, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 2026
SUNDRAM07 pushed a commit to SUNDRAM07/gemini-cli that referenced this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve Windows line ending and path separation bugs across CLI components

2 participants