Skip to content

Commit a2a1948

Browse files
committed
fix(web): keep a trailing colon on URLs
1 parent 15cdc46 commit a2a1948

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ describe("extractTerminalLinks", () => {
9898
]);
9999
});
100100

101+
it("keeps a trailing colon on URLs", () => {
102+
expect(extractTerminalLinks("GET https://example.test/items/foo:")).toEqual([
103+
{ kind: "url", text: "https://example.test/items/foo:", start: 4, end: 35 },
104+
]);
105+
});
106+
101107
it.each([
102108
["./main.go:10:5: undefined: x", "./main.go:10:5"],
103109
["/home/dev/app/src/main.c:10:5: error: expected ';'", "/home/dev/app/src/main.c:10:5"],

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ export interface WrappedTerminalLinkLine {
3434
const URL_PATTERN = /https?:\/\/[^\s"'`<>]+/giu;
3535
const FILE_PATH_PATTERN =
3636
/(?:~\/|\.{1,2}\/|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+(?::\d+){0,2}/g;
37-
const TRAILING_PUNCTUATION_PATTERN = /[.,;:!?]+$/;
38-
39-
function trimClosingDelimiters(value: string): string {
40-
let output = value.replace(TRAILING_PUNCTUATION_PATTERN, "");
37+
const TRAILING_PUNCTUATION_PATTERN = /[.,;!?]+$/;
38+
// Paths also drop a trailing colon: compilers end `file:line:col:` with one.
39+
const TRAILING_PATH_PUNCTUATION_PATTERN = /[.,;:!?]+$/;
40+
41+
function trimClosingDelimiters(value: string, kind: TerminalLinkKind): string {
42+
let output = value.replace(
43+
kind === "path" ? TRAILING_PATH_PUNCTUATION_PATTERN : TRAILING_PUNCTUATION_PATTERN,
44+
"",
45+
);
4146
if (output.length === 0) return output;
4247

4348
const trimUnbalanced = (open: string, close: string) => {
@@ -73,7 +78,7 @@ function collectMatches(
7378
const start = rawMatch.index ?? -1;
7479
if (start < 0 || raw.length === 0) continue;
7580

76-
const trimmed = trimClosingDelimiters(raw);
81+
const trimmed = trimClosingDelimiters(raw, kind);
7782
if (trimmed.length === 0) continue;
7883
if (kind === "path" && isTerminalUrl(trimmed)) continue;
7984

0 commit comments

Comments
 (0)