Skip to content

Commit ca084e1

Browse files
committed
fix(web): reject partial terminal URL schemes
1 parent cf4c210 commit ca084e1

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ describe("extractTerminalLinks", () => {
6767
);
6868
});
6969

70+
it("does not match supported schemes inside longer scheme names", () => {
71+
const line =
72+
"hotel:123 demagnet:foo x-mailto:[email protected] x+mailto:[email protected] x.mailto:[email protected]";
73+
74+
expect(extractTerminalLinks(line)).toEqual([]);
75+
});
76+
7077
it("trims trailing punctuation from links", () => {
7178
const line = "(https://example.com/docs), ./src/main.ts:12.";
7279
expect(extractTerminalLinks(line)).toEqual([

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ export interface WrappedTerminalLinkLine {
3838

3939
// Also matches the non-http schemes ghostty and other terminals linkify;
4040
// authority-style schemes require // while opaque ones take a bare payload.
41+
// The lookbehind prevents matching a supported scheme inside a longer RFC 3986 scheme name.
4142
const URL_PATTERN =
42-
/(?:https?|ftp|ssh|git|gemini|gopher):\/\/[^\s"'`<>]+|(?:mailto|tel|news|magnet):[^\s"'`<>:][^\s"'`<>]*/gi;
43+
/(?<![A-Za-z0-9+.-])(?:(?:https?|ftp|ssh|git|gemini|gopher):\/\/[^\s"'`<>]+|(?:mailto|tel|news|magnet):[^\s"'`<>:][^\s"'`<>]*)/gi;
4344
const FILE_PATH_PATTERN =
4445
/(?:~\/|\.{1,2}\/|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+(?::\d+){0,2}/g;
4546
const TRAILING_PUNCTUATION_PATTERN = /[.,;!?]+$/;

0 commit comments

Comments
 (0)