Skip to content

Better URL shortening in browser tab labels#306765

Merged
kycutler merged 2 commits intomainfrom
kycutler/urlshortening
Apr 1, 2026
Merged

Better URL shortening in browser tab labels#306765
kycutler merged 2 commits intomainfrom
kycutler/urlshortening

Conversation

@kycutler
Copy link
Copy Markdown
Contributor

Fixes #306412
Fixes #306528

@kycutler kycutler requested review from bpasero and Copilot March 31, 2026 14:15
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering bot commented Mar 31, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@jruales

Matched files:

  • src/vs/workbench/contrib/browserView/common/browserEditorInput.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves how browser editor tabs and descriptions display URLs by reducing noise from long query strings/fragments and ensuring URL paths can be shortened cleanly (avoiding malformed-looking http:/… renderings).

Changes:

  • Update BrowserEditorInput labeling to use verbosity-aware URL descriptions (short/medium/long) and prefer page titles for tab names.
  • Extend labels.shorten() to recognize scheme:// URLs and shorten their path segments correctly (including trailing-slash preservation).
  • Add unit tests covering URL shortening behavior (including mixed URL + filesystem path inputs).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/vs/workbench/contrib/browserView/common/browserEditorInput.ts Adds verbosity-aware URL description formatting and adjusts name/title composition for browser tabs/tooltips.
src/vs/base/common/labels.ts Teaches shorten() to detect scheme:// URLs and treat / as the separator for those paths (fixing http:/…-style outputs).
src/vs/base/test/common/labels.test.ts Adds coverage for URL shortening scenarios on Windows and non-Windows.

Comment thread src/vs/workbench/contrib/browserView/common/browserEditorInput.ts
Comment thread src/vs/workbench/contrib/browserView/common/browserEditorInput.ts
@bpasero
Copy link
Copy Markdown
Member

bpasero commented Apr 1, 2026

Code Review: shorten() URL scheme support & trailing slash preservation

# Severity Issue Location Details
1 High Bug: URLs produce empty leading segment labels.ts For file:///some/path, after extracting scheme prefix , the remaining trimmedPath is /some/path. Since the URL branch is exclusive (if/else if), the next branch that strips a leading / is never reached. Splitting /some/path by / yields ['', 'some', 'path']. The empty segment at index 0 will corrupt the shortening logic — it can cause false-positive substring matches, produce results with leading separators like //some, and break the disk-drive prefix heuristic (segments[0].endsWith(':') evaluates on ''). Fix: after extracting the URL prefix, strip the leading / from trimmedPath and append it to prefix (e.g. prefix becomes ).
2 High Missing tests labels.test.ts The diff adds ~20 lines of non-trivial logic (URL detection, separator override, trailing-slash preservation) but no tests. Per project guidelines, changes >10 lines require tests. At minimum, tests should cover: (a) simple URL paths like vscode-remote://auth/a/b, (b) triple-slash URLs, (c) mixed URL and file-system paths, (d) paths with trailing slashes, and (e) the new trailing-slash preservation branch.
3 Medium Deprecated substr() in new code labels.ts The four new substr() calls use a deprecated API. While the surrounding existing code also uses substr, new code should prefer substring(). substr(start, length) and substring(start, end) have different semantics — using substr here works but risks confusion and lint warnings.
4 Medium Cross-path comparison mismatch with mixed separators labels.ts When one path is a URL (separator forced to /) and another is a Windows path (separator \), the uniqueness check paths[otherPathIndex].indexOf(subpath) compares subpaths split with / against raw paths with \. This means a URL subpath host/dir would never match inside host\dir, potentially causing the algorithm to return a less-shortened path than necessary. The pathSeparator override is per-path but the cross-path comparison doesn't normalize separators.
5 Low Redundant indexOf('//') computed twice labels.ts trimmedPath.indexOf('//') is called twice on labels.ts and labels.ts. Should compute once into a local variable: const schemeEnd = trimmedPath.indexOf('//') + 2;.
6 Low Trailing-slash logic only fires at specific subpath positions labels.ts The trailing-slash preservation only works when start + subpathLength === segments.length - 1. If additional trailing empty segments exist (e.g. path/to/dir//), the condition won't match and the trailing slash(es) would be replaced by . This is edge-case but worth a comment to make the intent explicit.
7 Info Regex could be documented labels.ts urlSchemaRegexp — the \\ inside the character class [^:/\\?#] prevents matching Windows drive-style paths like C:\, which is an important subtlety. A brief comment explaining why backslash is excluded would help future readers.

Summary

The two high-severity items should be addressed before merging: the URL bug (empty segment corruption) and the missing test coverage. The substr deprecation and redundant indexOf are straightforward cleanups. The cross-path separator mismatch is a design limitation worth acknowledging — if mixed URL/Windows paths are expected, the indexOf comparison needs normalization.

Copy link
Copy Markdown
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some local CCR for you to consider, not sure if all applicable.

@kycutler kycutler enabled auto-merge (squash) April 1, 2026 15:52
@kycutler kycutler merged commit 0bb51dd into main Apr 1, 2026
19 checks passed
@kycutler kycutler deleted the kycutler/urlshortening branch April 1, 2026 15:58
@vs-code-engineering vs-code-engineering bot added this to the 1.115.0 milestone Apr 1, 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.

Tab title rendered with extra ... Browser tabs too long

3 participants