fix(core): make isWithinRoot case-insensitive on Windows - #29247
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
📊 PR Size: size/S
|
|
CLA check is red until the Google CLA is signed at https://cla.developers.google.com/ |
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 resolves an issue where path validation in the core package was failing on Windows due to case-sensitive comparisons. By migrating the logic to use the established isSubpath utility, the implementation now correctly accounts for Windows' case-insensitive file system behavior, improving the reliability of IDE file system routing and path normalization. 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
|
|
I signed the CLA. |
There was a problem hiding this comment.
Code Review
This pull request refactors the isWithinRoot utility in packages/core/src/utils/fileUtils.ts to use the isSubpath helper, simplifying the path comparison and macOS symlink handling. It also introduces Windows-specific unit tests. The feedback points out that mocking process.platform inside a block already skipped on non-Windows platforms is redundant and that stubbing the global process object is risky and should be removed.
| const mockPlatform = (platform: string) => { | ||
| vi.stubGlobal( | ||
| 'process', | ||
| Object.create(process, { | ||
| platform: { | ||
| get: () => platform, | ||
| }, | ||
| }), | ||
| ); | ||
| }; | ||
|
|
||
| beforeEach(() => mockPlatform('win32')); | ||
| afterEach(() => vi.unstubAllGlobals()); |
There was a problem hiding this comment.
Since this describe block is already skipped on non-Windows platforms using describe.skipIf(process.platform !== 'win32'), the tests inside will only ever execute on Windows. Consequently, mocking process.platform to 'win32' is completely redundant.
Furthermore, stubbing the global process object using Object.create(process, ...) can be risky in Vitest/Node.js environments as it can interfere with other native properties or event listeners on process. Removing this redundant mocking simplifies the test and avoids potential side-effects.
There was a problem hiding this comment.
Removed the stub. The suite is already skipIf non-win32, so the mock was redundant.
Summary
isWithinRoot()compared paths with case-sensitive===/startsWith. On Windows that rejects valid in-root paths when the drive letter or folder casing differs (c:\...vsC:\...), which breaks ACP/IDE FS routing and ignore-path normalization.Reuse
isSubpath(), which already does a case-insensitive check on Windows (and Darwin).Details
isSubpath()already usespath.win32and case-insensitiverelative()on Windows.isWithinRoot()was a second containment helper that did not.macOS
/privatealias handling is unchanged; it now also goes throughisSubpath().Related Issues
Fixes #29000
How to Validate
isWithinRoot('C:\\Users\\proj\\file.ts', 'c:\\Users\\proj')— should betrue.packages/coretests:isWithinRoot on Windows(drive-letter casing, path-component casing, different drive).isWithinRootcases still pass on POSIX.Pre-Merge Checklist