Skip to content

Commit 150b1b7

Browse files
MarcoDotIOclaude
andcommitted
fix(web): keep only the URL-scheme exclusion for terminal links
Linking `file://` URLs to the file they name is a new behaviour, so it is left out of this fix; such URLs are now simply not linked instead of producing a broken `e:///…` link. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b5f680b commit 150b1b7

2 files changed

Lines changed: 6 additions & 46 deletions

File tree

‎apps/web/src/terminal-links.test.ts‎

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,10 @@ describe("extractTerminalLinks", () => {
175175
]);
176176
});
177177

178-
it.each([
179-
[
180-
" at main (file:///Users/jane/app/src/index.mjs:3:7)",
181-
"file:///Users/jane/app/src/index.mjs:3:7",
182-
"/Users/jane/app/src/index.mjs:3:7",
183-
],
184-
[
185-
"open file:///Users/jane/My%20Reports/index.html",
186-
"file:///Users/jane/My%20Reports/index.html",
187-
"/Users/jane/My Reports/index.html",
188-
],
189-
[
190-
"at file:///C:/app/src/index.mjs:3:7",
191-
"file:///C:/app/src/index.mjs:3:7",
192-
"C:/app/src/index.mjs:3:7",
193-
],
194-
])("links the file a file URL names in %s", (line, url, text) => {
195-
const start = line.indexOf(url);
196-
expect(extractTerminalLinks(line)).toEqual([
197-
{ kind: "path", text, start, end: start + url.length },
198-
]);
178+
it("does not link a mangled path out of a file URL", () => {
179+
expect(extractTerminalLinks(" at main (file:///Users/jane/app/src/index.mjs:3:7)")).toEqual(
180+
[],
181+
);
199182
});
200183

201184
it("keeps a question mark inside a filesystem path", () => {

‎apps/web/src/terminal-links.ts‎

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { parseFileUrlHref } from "@t3tools/shared/fileLinks";
2-
import { safeDecodeURIComponent } from "@t3tools/shared/markdownLinks";
3-
41
import { isMacPlatform } from "./lib/utils";
52

63
export type TerminalLinkKind = "url" | "path";
@@ -31,11 +28,9 @@ export interface WrappedTerminalLinkLine {
3128

3229
const URL_PATTERN = /https?:\/\/[^\s"'`<>]+/giu;
3330
// A URL's tail is not a file path even when it looks like one (`redis://host/0`,
34-
// `s3://bucket/key`); `file:` URLs link to the file they name instead. One-letter
35-
// schemes stay Windows drives, and the lookbehinds keep long letter runs from being
36-
// rescanned at every suffix.
31+
// `s3://bucket/key`). One-letter schemes stay Windows drives, and the lookbehind
32+
// keeps long letter runs from being rescanned at every suffix.
3733
const SCHEME_URL_PATTERN = /(?<![A-Za-z\d+.-])[A-Za-z][A-Za-z\d+.-]+:\/\/[^\s"'`<>]+/gu;
38-
const FILE_URL_PATTERN = /(?<![A-Za-z\d+.-])file:\/\/[^\s"'`<>]+/giu;
3934
// Bare paths start only at a segment boundary: hover detection runs this on
4035
// every frame, so separator-free output must not be rescanned at every suffix.
4136
const FILE_PATH_PATTERN =
@@ -112,22 +107,6 @@ function collectMatches(
112107
return matches;
113108
}
114109

115-
function collectFileUrlMatches(line: string): TerminalLinkMatch[] {
116-
const matches: TerminalLinkMatch[] = [];
117-
for (const match of line.matchAll(FILE_URL_PATTERN)) {
118-
const raw = trimClosingDelimiters(match[0], "path");
119-
const target = parseFileUrlHref(raw);
120-
if (target === null) continue;
121-
matches.push({
122-
kind: "path",
123-
text: safeDecodeURIComponent(target.path),
124-
start: match.index,
125-
end: match.index + raw.length,
126-
});
127-
}
128-
return matches;
129-
}
130-
131110
function matchRanges(line: string, pattern: RegExp): Array<{ start: number; end: number }> {
132111
return Array.from(line.matchAll(pattern), (match) => ({
133112
start: match.index,
@@ -141,15 +120,13 @@ export function extractTerminalLinks(line: string): TerminalLinkMatch[] {
141120
...matchRanges(line, SCHEME_URL_PATTERN),
142121
];
143122
const urlMatches = collectMatches(line, "url", URL_PATTERN, []);
144-
const fileUrlMatches = collectFileUrlMatches(line);
145123
const quotedMatches = collectMatches(line, "path", QUOTED_FILE_PATH_PATTERN, urlMatches);
146124
const pathMatches = collectMatches(line, "path", FILE_PATH_PATTERN, [
147125
...urlMatches,
148126
...quotedMatches,
149127
]);
150128
return [
151129
...urlMatches,
152-
...fileUrlMatches,
153130
...[...quotedMatches, ...pathMatches].filter(
154131
(match) => !nonPathRanges.some((range) => overlaps(match, range)),
155132
),

0 commit comments

Comments
 (0)