Better URL shortening in browser tab labels#306765
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @jrualesMatched files:
|
There was a problem hiding this comment.
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
BrowserEditorInputlabeling to use verbosity-aware URL descriptions (short/medium/long) and prefer page titles for tab names. - Extend
labels.shorten()to recognizescheme://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. |
Code Review:
|
| # | 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.
bpasero
left a comment
There was a problem hiding this comment.
Some local CCR for you to consider, not sure if all applicable.
Fixes #306412
Fixes #306528