Skip to content
Merged
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
9 changes: 9 additions & 0 deletions packages/client-runtime/src/markdownLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ describe("inlineCodeFilePathCandidate", () => {
["127.0.0.1:3000", null],
["example.com/index.html", null],
["example.pl/index.html", null],
["z-ai/glm-5.3", null],
["z-ai/glm-5.3:12", null],
["python/3.12", null],
["Qwen/Qwen2.5-Coder", null],
["meta-llama/Llama-3.1-8B", null],
["share/man/ls.1", "share/man/ls.1"],
["usr/lib/libfoo.so.1", "usr/lib/libfoo.so.1"],
["vendor/jquery-3.6.0.min.js", "vendor/jquery-3.6.0.min.js"],
["./models/glm-5.3", "./models/glm-5.3"],
])("distinguishes file paths from code and hostnames in %s", (source, candidate) => {
expect(inlineCodeFilePathCandidate(source)).toBe(candidate);
});
Expand Down
4 changes: 4 additions & 0 deletions packages/client-runtime/src/markdownLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const POSITION_ONLY_PATTERN = /^\d+(?::\d+)?$/;
const INLINE_CODE_DISQUALIFIER_PATTERN = /[\s`]/;
const PATH_SEPARATOR_PATTERN = /[\\/]/;
const FILE_EXTENSION_PATTERN = /\.[A-Za-z0-9_-]+$/;
// A final dot between digits marks a version or model id (`glm-5.3`,
// `Qwen2.5-Coder`), not an extension. `ls.1` and `libfoo.so.1` stay files.
const VERSION_SUFFIX_PATTERN = /\d\.\d[^.]*$/;
const NUMERIC_DOTTED_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.
Expand Down Expand Up @@ -176,6 +179,7 @@ export function inlineCodeFilePathCandidate(codeText: string): string | null {
.replace(/[/\\]+$/, "")
.split(/[\\/]/)
.at(-1) ?? "";
if (VERSION_SUFFIX_PATTERN.test(basename)) return null;
if (!hasPosition && !FILE_EXTENSION_PATTERN.test(basename)) return null;
}
return candidate;
Expand Down
Loading