Skip to content

Fix drag and drop escaping#18965

Merged
scidomino merged 1 commit into
mainfrom
tomm_2drag2drop
Feb 13, 2026
Merged

Fix drag and drop escaping#18965
scidomino merged 1 commit into
mainfrom
tomm_2drag2drop

Conversation

@scidomino

@scidomino scidomino commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes drag-and-drop parsing to fully support windows and POSIX

Details

Drag-and-drop file paths are escaped in several different styles which were previously not always supported:

  • Bare (only if there are no special chars): /path/to/myfile.png
  • Wrapped in double quotes (Windows only): "/path/to/my file~!.png"
  • Escaped with backslashes (POSIX only): /path/to/my\ file~!.png
  • Wrapped in single quotes: '/path/to/my file~!.png'

This PR allows us to accept pretty much anything we get.

This also changes our code to use a consistent OS-specific escaping for at-paths in the text:

  • Windows:
    • If contains special characters: Wrapped in double quotes
    • Otherwise: Bare
  • POSIX: Escaped with backslashes

Also, to reduce the aggressiveness of at-prefixing, we will only prefix at-paths if all the paths in a paste are valid.

Related Issues

For #17135

How to Validate

drag-and-drop file paths in mac, linux, and windows.

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

@scidomino scidomino requested a review from a team as a code owner February 12, 2026 23:14
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @scidomino, 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 application's ability to process file paths from drag-and-drop operations, ensuring full compatibility across Windows, POSIX, and Mac systems. The changes standardize how file paths are interpreted and escaped, leading to a more reliable and consistent user experience when interacting with file references, regardless of the operating system or the specific escaping style used for the path.

Highlights

  • Enhanced Drag-and-Drop Path Parsing: Improved the parsing logic for drag-and-drop file paths to robustly handle various escaping styles across Windows, POSIX, and Mac operating systems, including bare paths, double-quoted paths, backslash-escaped paths, and single-quoted paths.
  • Standardized OS-Specific Path Escaping: Implemented consistent OS-specific escaping for @ paths: Windows paths are now double-quoted if they contain special characters, while POSIX paths use individual backslash escaping for special characters.
  • Refactored Path Utility Functions: Rewrote the core escapePath and unescapePath utility functions to be platform-aware, ensuring correct handling of path formats and special characters based on the operating system.
  • Comprehensive Test Coverage: Added extensive unit tests, including parameterized tests and platform mocking, to validate the new drag-and-drop parsing and OS-specific escaping logic across different environments.
Changelog
  • packages/cli/src/ui/components/shared/text-buffer.test.ts
    • Added a mockPlatform helper function to facilitate platform-specific testing.
    • Ensured vi.unstubAllGlobals() is called in afterEach to clean up global mocks.
    • Introduced beforeEach hooks to set the platform for getTransformedImagePath tests.
  • packages/cli/src/ui/components/shared/text-buffer.ts
    • Simplified the call to parsePastedPaths by removing redundant intermediate path trimming and quote matching.
  • packages/cli/src/ui/hooks/atCommandProcessor.test.ts
    • Added vi.unstubAllGlobals() to afterEach for proper test isolation.
    • Included a new test case to verify correct handling of double-quoted paths with spaces on Windows.
  • packages/cli/src/ui/hooks/atCommandProcessor.ts
    • Updated AT_COMMAND_PATH_REGEX_SOURCE to recognize double-quoted strings for improved path parsing.
    • Modified parseAllAtCommands to strip the leading @ symbol before calling unescapePath, allowing unescapePath to correctly process quoted paths on Windows.
  • packages/cli/src/ui/utils/clipboardUtils.test.ts
    • Introduced a mockPlatform helper for platform-specific test setup.
    • Removed the originalPlatform variable and added vi.unstubAllGlobals() to afterEach.
    • Renamed splitEscapedPaths to splitDragAndDropPaths and added comprehensive parameterized tests for both POSIX and Windows path splitting scenarios.
    • Refactored parsePastedPaths tests to be grouped by platform, ensuring accurate validation of OS-specific behavior.
  • packages/cli/src/ui/utils/clipboardUtils.ts
    • Removed the unescapePath import as its logic is now handled internally or by the core paths.ts module.
    • Deleted the SHELL_SPECIAL_CHARS constant.
    • Replaced splitEscapedPaths with a new splitDragAndDropPaths function, implementing a state-machine-based parsing logic to handle various quoting and escaping styles.
    • Updated parsePastedPaths to utilize the new splitDragAndDropPaths and the platform-aware escapePath function.
    • Removed initial quote matching logic from parsePastedPaths as it's now handled by splitDragAndDropPaths.
  • packages/core/src/utils/paths.test.ts
    • Updated vitest imports to include afterEach and beforeEach.
    • Refactored escapePath and unescapePath tests to use mockPlatform for platform-specific test execution.
    • Updated isSubpath tests to use mockPlatform and afterEach for consistent environment control.
  • packages/core/src/utils/paths.ts
    • Removed the direct import of process and the SHELL_SPECIAL_CHARS constant.
    • Completely rewrote escapePath to implement OS-specific escaping: double-quoting for Windows paths with special characters, and backslash escaping for POSIX paths.
    • Completely rewrote unescapePath to implement OS-specific unescaping: removing quotes for Windows paths and removing backslashes for POSIX paths.
    • Updated isSubpath to directly use process.platform for platform detection.
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.

@scidomino

Copy link
Copy Markdown
Collaborator Author

/gemini review

@github-actions

github-actions Bot commented Feb 12, 2026

Copy link
Copy Markdown

Size Change: -171 B (0%)

Total Size: 24.4 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.4 MB -171 B (0%)
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@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 introduces significant improvements to file path parsing for drag-and-drop functionality, aiming to provide robust support across Windows, POSIX, and macOS. The changes include refactoring path splitting and escaping logic into more centralized and platform-aware utilities, along with an expansion of test coverage to validate these new behaviors. While the direction is excellent, I've identified a critical regression in the POSIX path escaping logic that could lead to incorrect behavior, a bug in parsing complex quoted paths, and a minor issue in the test setup that could lead to flaky tests. Addressing these points will help ensure the new implementation is as robust as intended.

Comment thread packages/core/src/utils/paths.ts
Comment thread packages/cli/src/ui/utils/clipboardUtils.test.ts Outdated
Comment thread packages/cli/src/ui/utils/clipboardUtils.ts Outdated
@scidomino scidomino marked this pull request as draft February 12, 2026 23:22

@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 significantly improves the handling of drag-and-drop file paths by introducing more robust, platform-aware parsing and escaping logic for both POSIX and Windows. The changes refactor path utilities and update regular expressions to correctly handle various path formats, including quoted paths. The accompanying tests have been greatly expanded, which is excellent. I found one critical issue in a test file that will cause the build to fail, but otherwise, the changes are solid.

Comment thread packages/cli/src/ui/utils/clipboardUtils.test.ts Outdated
@scidomino

Copy link
Copy Markdown
Collaborator 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 significantly improves the handling of file path escaping and parsing for drag-and-drop functionality, making it more robust across both Windows and POSIX environments. The changes introduce platform-specific escaping logic and a more sophisticated parser for various path formats. The test suite has also been substantially enhanced to cover these new scenarios. I've identified one potential issue in the new path parser where it doesn't correctly handle escaped characters within double-quoted strings on POSIX systems, which could lead to incorrect path parsing in some edge cases.

Comment thread packages/cli/src/ui/utils/clipboardUtils.ts
@scidomino scidomino marked this pull request as ready for review February 13, 2026 00:22
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 13, 2026
'path\\\\\\\\with\\ space.txt',
);
});
const mockPlatform = (platform: string) => {

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.

nit: as a followup can you cleanup these and other calls to mock the platform with a standard helper util used by all tests in Gemini CLI that mock the platform.

@jacob314 jacob314 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.

lgtm

@scidomino scidomino enabled auto-merge February 13, 2026 02:19
@scidomino scidomino added this pull request to the merge queue Feb 13, 2026
Merged via the queue into main with commit d82f669 Feb 13, 2026
26 of 27 checks passed
@scidomino scidomino deleted the tomm_2drag2drop branch February 13, 2026 02:38
@github-actions

Copy link
Copy Markdown

Patch workflow(s) dispatched successfully!

📋 Details:

  • Channels: stable
  • Commit: d82f66973fa0eeea0a09d19ce1ec08bb69a96449
  • Workflows Created: 1

🔗 Track Progress:

@scidomino

Copy link
Copy Markdown
Collaborator Author

@bugdotexe very clever, but it won't work without someone with the right permissions approving the github action.

cocosheng-g pushed a commit that referenced this pull request May 6, 2026
@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large sized 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.

3 participants