Repository navigation
terminal: fix collapseTildePath substring collisions and exact home collapse - #343203
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Fixes incorrect ~ collapsing in collapseTildePath by enforcing directory-boundary matching and formatting the exact home directory as ~ (not ~/), with accompanying unit tests.
Changes:
- Replace substring matching with
startsWith(normalizedUserHome + '/')to avoid prefix/substring collisions. - Return
~when the path is exactly the home directory (with optional trailing separator). - Add unit tests covering exact-home collapsing and non-collapsing for substring/prefix cases.
| File | Description |
|---|---|
| src/vs/platform/terminal/common/terminalEnvironment.ts | Tightens home matching logic and returns ~ for exact-home paths |
| src/vs/platform/terminal/test/common/terminalEnvironment.test.ts | Adds regression tests for exact-home behavior and collision avoidance |
Review effort: Lite
|
Addressed in 91347a0 by adding drive root guard and regression tests. |
Megan Rogge (meganrogge)
left a comment
There was a problem hiding this comment.
Thanks for the fix!
There was a problem hiding this comment.
🟡 Changes recommended
The anchored comparison rejects valid Windows OSC 7 home paths with a URI-style leading slash, causing command-history entries to display the full path instead of collapsing it.
1 open issue
2 resolved since last review
Review effort: Max
|
We should address the comment Aditya Kumar Yadav (@Aditya-kumar-yadav) |
Dmitriy Vasyura (dmitrivMS)
left a comment
There was a problem hiding this comment.
Please consider CCR comment
Head branch was pushed to by a user without write access
6b05512
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Fix hygiene copyright-header check and eliminate stray CR line endings across terminalEnvironment and its test suite.
Head branch was pushed to by a user without write access



Summary of Changes
Fix substring & prefix collisions in
collapseTildePath:collapseTildePathpreviously used.includes(normalizedUserHome). This caused incorrect path collapses when:/home/user_admin/projectwith home/home/usercollapsed to~/admin/project)./var/log/home/user/appcollapsed to~/g/home/user/app).C:\Users\user_backup\codewith homeC:\Users\usercollapsed to~\_backup\code.This change replaces
.includes()with directory boundary checks (.startsWith(normalizedUserHome + '/')).Format exact home directory as
~:When
pathmatchesuserHome(with or without a trailing separator),collapseTildePathnow returns'~'instead of'~/'(or~\).Root directory guard:
Added a guard when
userHomeis'/'or\to prevent treating the filesystem root as a user home directory.Verification
Ran unit tests: