Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/web/src/markdown-links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ describe("resolveMarkdownFileLinkTarget", () => {
it("does not treat app routes as file links", () => {
expect(resolveMarkdownFileLinkTarget("/chat/settings")).toBeNull();
});

it("does not treat device nodes and kernel state as file links", () => {
expect(resolveMarkdownFileLinkTarget("/dev/kvm")).toBeNull();
expect(resolveMarkdownFileLinkTarget("/dev/null")).toBeNull();
expect(resolveMarkdownFileLinkTarget("/proc/cpuinfo")).toBeNull();
expect(resolveMarkdownFileLinkTarget("/sys/class/net/eth0")).toBeNull();
});
});

describe("resolveInlineCodeFileLinkMeta", () => {
Expand All @@ -152,6 +159,15 @@ describe("resolveInlineCodeFileLinkMeta", () => {
expect(resolveInlineCodeFileLinkMeta("/chat/settings")).toBeNull();
});

it("ignores device nodes and kernel state", () => {
expect(resolveInlineCodeFileLinkMeta("/dev/kvm", "/Users/julius/project")).toBeNull();
expect(resolveInlineCodeFileLinkMeta("/dev/null", "/Users/julius/project")).toBeNull();
expect(resolveInlineCodeFileLinkMeta("/proc/cpuinfo", "/Users/julius/project")).toBeNull();
expect(
resolveInlineCodeFileLinkMeta("/sys/class/net/eth0", "/Users/julius/project"),
).toBeNull();
});

it("links windows drive paths", () => {
expect(resolveInlineCodeFileLinkMeta("C:\\Users\\mike\\project\\src\\main.ts")).toMatchObject({
basename: "main.ts",
Expand Down
10 changes: 4 additions & 6 deletions apps/web/src/markdown-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const RELATIVE_FILE_NAME_PATTERN = /^[A-Za-z0-9._-]+\.[A-Za-z0-9_-]+(?::\d+){0,2
const POSITION_SUFFIX_PATTERN = /:\d+(?::\d+)?$/;
const POSITION_ONLY_PATTERN = /^\d+(?::\d+)?$/;
// Standard OS and dev-container roots; deliberately excludes app-route-ish
// prefixes like /app/ or /chat/ so SPA routes never read as files.
// prefixes like /app/ or /chat/ so SPA routes never read as files, and roots
// holding device nodes, kernel state, or boot images rather than editable
// files. Entries under an excluded root still link when they carry a file
// extension or a :line suffix.
const POSIX_FILE_ROOT_PREFIXES = [
"/Users/",
"/home/",
Expand All @@ -28,11 +31,6 @@ const POSIX_FILE_ROOT_PREFIXES = [
"/lib/",
"/lib64/",
"/srv/",
"/dev/",
"/proc/",
"/sys/",
"/run/",
"/boot/",
"/media/",
"/workspace/",
"/workspaces/",
Expand Down
Loading