Repository navigation
fix: path, URI, JSON edit utility bugs - #334259
Martin Aeschlimann (aeschli) merged 8 commits into
Conversation
- extpath.ts: isRootOrDriveLetter checked path.length instead of pathNormalized.length, causing C:\\ (len 4) to be rejected even though it normalizes to the valid root C:\ (len 3) - jsonEdit.ts: last-array-element removal used parentEndOffset - 2 instead of - 1, leaving a stale character before the closing ] - terminalEnvironment.ts: escapeNonWindowsPath singleQuotes branch for bash/sh/zsh/git-bash used plain '...' quoting, which cannot contain escaped single quotes; fixed to $'...' (ANSI-C quoting) matching the bothQuotes branch - terminalEnvironment.ts: collapseTildePath used String.includes() instead of startsWith(), allowing a path like /home/virajfoo/x to incorrectly collapse when userHome is /home/viraj - uri.ts: password component in userinfo was encoded with isAuthority=true, leaving ':' unencoded in passwords; fixed to false
There was a problem hiding this comment.
🟡 Changes recommended
The changes regress bare drive detection, mishandle POSIX sh, and do not fully encode passwords containing multiple colons.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes correctness issues in shared path, URI, JSON editing, and terminal utilities.
Changes:
- Corrects normalized path and tilde-boundary checks.
- Adjusts URI password encoding and JSON array removal spans.
- Revises shell quoting for embedded single quotes.
File summaries
| File | Description |
|---|---|
src/vs/base/common/extpath.ts |
Uses normalized lengths for root detection. |
src/vs/base/common/jsonEdit.ts |
Corrects last-array-element deletion range. |
src/vs/base/common/uri.ts |
Changes password-component encoding. |
src/vs/platform/terminal/common/terminalEnvironment.ts |
Updates shell quoting and home-path matching. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 5
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…, POSIX sh quoting
|
@microsoft-github-policy-service agree |
…dePath collisions
Martin Aeschlimann (aeschli)
left a comment
There was a problem hiding this comment.
Please create a separate PR for the terminal issue.
|
Done, moved the terminal changes to #334988 |
|
Copilot please review |
The early-return guard also needs path.length > 3, not
pathNormalized.length > 3. normalize('D:') can return 'D:.'
(3 chars), making pathNormalized.length === 3 while the original
path is only 2 chars — the guard must use the original path length.
There was a problem hiding this comment.
🟡 Changes recommended
Add URI password-colon regression coverage and include or remove the unimplemented path and terminal fixes.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
src/vs/base/common/uri.ts:685
- Please add a regression case for a password containing a colon, for example an authority like
user:pa:ss@hostexpectinguser:pa%3Ass@host. The existing user-info test only has one colon, so it does not verify thatindexOfselects the user/password delimiter or that the password-specific encoding change preserves the remaining colon correctly.
} else {
// <user>:<pass>@<auth>
res += encoder(userinfo.substr(0, idx), false, false);
res += ':';
res += encoder(userinfo.substr(idx + 1), false, false);
src/vs/base/common/uri.ts:678
- The PR description claims fixes in
extpath.tsandterminalEnvironment.ts, but neither file is changed in this patch, so those reported bugs remain:isRootOrDriveLetterstill uses the unnormalized length (extpath.ts:323,328),collapseTildePathstill uses an unboundedincludesmatch (terminalEnvironment.ts:99), and the single-quote branches still emit invalid POSIX quoting (terminalEnvironment.ts:38,62). Please include the corresponding implementation and regression tests, or remove those fixes from the PR description.
idx = userinfo.indexOf(':');
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
The formatter expands the remaining array, so removing index 1 from [1,2] gives '[\n 1\n]', not '[1]'. This fixes the failing JSON - edits test.
54920a6 to
f7be48b
Compare
922ce6a
into
microsoft:main

Fixes two small bugs in base utilities.
jsonEdit.ts: removing the last array element left a stray character
When removing the last element of an array, the deletion length was computed as
parentEndOffset - 2 - offset.parentEndOffsetis one past the closing], so the correct length isparentEndOffset - 1 - offset. The extra- 1stopped the edit one character short. In a compact array like[1,2]that is easy to hit, because there is no whitespace between the last element and the]to hide it.Added a regression test that removes index 1 from
[1,2].uri.ts: userinfo with a colon in the password
_asFormattedsplit userinfo on the last colon (lastIndexOf), so a password containing:was cut in the wrong place. It now splits on the first colon, since the user name can't contain one. The password is also now encoded withisAuthority = false, so a:in it is percent-encoded and can't be mistaken for the separator.I haven't added a test for this one yet.