fix: path, URI, JSON edit utility bugs by VirajMishra1 · Pull Request #334259 · microsoft/vscode · GitHub
Skip to content

fix: path, URI, JSON edit utility bugs - #334259

Merged
Martin Aeschlimann (aeschli) merged 8 commits into
microsoft:mainfrom
VirajMishra1:fix-path-uri-util-bugs
Oct 15, 2026
Merged

Martin Aeschlimann (aeschli) merged 8 commits into
microsoft:mainfrom
VirajMishra1:fix-path-uri-util-bugs

Conversation

@VirajMishra1

@VirajMishra1 Viraj Mishra (VirajMishra1) commented Sep 3, 2026 •

Copy link
Copy Markdown

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. parentEndOffset is one past the closing ], so the correct length is parentEndOffset - 1 - offset. The extra - 1 stopped 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

_asFormatted split 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 with isAuthority = 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.

- 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
Copilot AI balanced review requested due to automatic review settings September 3, 2026 14:18
@vs-code-engineering

Copy link
Copy Markdown
Contributor

Copilot AI 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.

🟡 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.

Comment thread src/vs/base/common/extpath.ts Outdated
Comment thread src/vs/base/common/uri.ts
Comment thread src/vs/platform/terminal/common/terminalEnvironment.ts Outdated
Comment thread src/vs/base/common/jsonEdit.ts
Comment thread src/vs/platform/terminal/common/terminalEnvironment.ts Outdated
@VirajMishra1

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

Please create a separate PR for the terminal issue.

@VirajMishra1

Copy link
Copy Markdown
Author

Done, moved the terminal changes to #334988

@aeschli

Copy link
Copy Markdown
Contributor

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.

Copilot AI 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.

🟡 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@host expecting user:pa%3Ass@host. The existing user-info test only has one colon, so it does not verify that indexOf selects 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.ts and terminalEnvironment.ts, but neither file is changed in this patch, so those reported bugs remain: isRootOrDriveLetter still uses the unnormalized length (extpath.ts:323,328), collapseTildePath still uses an unbounded includes match (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.
@aeschli
Martin Aeschlimann (aeschli) merged commit 922ce6a into microsoft:main Oct 15, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.143.0 milestone Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants