fix: path, URI, JSON edit utility bugs - #334259
fix: path, URI, JSON edit utility bugs#334259Viraj Mishra (VirajMishra1) wants to merge 6 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 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
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.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
| const offset = previous.offset + previous.length; | ||
| const parentEndOffset = parent.offset + parent.length; | ||
| edit = { offset, length: parentEndOffset - 2 - offset, content: '' }; | ||
| edit = { offset, length: parentEndOffset - 1 - offset, content: '' }; |
fix: path, URI, JSON edit, and shell quoting bugs in utility modules
Five distinct correctness bugs across four files:
1. extpath.ts -- isRootOrDriveLetter checks wrong length variable
isRootOrDriveLetternormalizes the path then guards onpath.lengthinsteadof
pathNormalized.length. A path likeC:\\(4 chars) normalizes toC:\(3 chars), but
path.length > 3incorrectly rejects it. Same issue on thedrive-letter-only
=== 2check.2. jsonEdit.ts -- last-array-element removal corrupts the array
The deletion span was computed as
parentEndOffset - 2 - offset.parentEndOffsetis one past the closing], so the correct span isparentEndOffset - 1 - offset. The extra-1left a stale character before], producing invalid JSON after removing the last array element.3. terminalEnvironment.ts -- escapeNonWindowsPath uses invalid POSIX quoting
The
singleQuotesbranch produced'path with '\'' embedded quote'.Single-quoted strings in POSIX sh/bash/zsh are literal --
\'inside them isnot an escape sequence, it ends the string and emits a literal backslash-quote.
Fixed to
$'...'(ANSI-C quoting), which correctly handles embedded singlequotes and matches the existing
bothQuotesbranch.4. terminalEnvironment.ts -- collapseTildePath matches home path anywhere
normalizedPath.includes(normalizedUserHome)matches the home directoryanywhere in the path, e.g.
/tmp/backup/home/viraj/filewould incorrectlycollapse. Also susceptible to prefix collisions like
/home/virajfoo.Fixed to
normalizedPath.startsWith(normalizedUserHome + '/')with anadditional equality check for the exact-home case.
5. uri.ts -- password in userinfo not fully percent-encoded
The password segment was encoded with
encoder(..., false, true)(
isAuthority=true), which leaves:unencoded (safe in hostnames).Per RFC 3986 ss. 3.2.1,
:inside a password MUST be percent-encoded.Fixed to
encoder(..., false, false).