Skip to content

Commit 450620e

Browse files
committed
fix(markdown): match Windows file-link labels case-insensitively
1 parent d00e8ea commit 450620e

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎packages/client-runtime/src/markdownLinks.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,8 @@ describe("isMarkdownFileLinkLabel", () => {
212212
);
213213
expect(isMarkdownFileLinkLabel("my file.ts", "/repo/my%20file.ts#L12")).toBe(true);
214214
});
215+
it("matches Windows paths regardless of case", () => {
216+
expect(isMarkdownFileLinkLabel("SRC\\EXAMPLE.TS", "C:\\repo\\src\\example.ts")).toBe(true);
217+
expect(isMarkdownFileLinkLabel("SRC/EXAMPLE.TS", "/repo/src/example.ts")).toBe(false);
218+
});
215219
});

‎packages/client-runtime/src/markdownLinks.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,15 @@ export function isMarkdownFileLinkLabel(label: string, href: string): boolean {
349349
if (!label.trim()) return true;
350350
const target = parseMarkdownFileLink(href);
351351
if (!target) return false;
352-
const path = (parseMarkdownFileLink(label)?.path ?? splitFilePathPosition(label.trim()).path)
353-
.replaceAll("\\", "/")
354-
.replace(/^\.\//, "")
355-
.replace(/([^/:])\/+$/, "$1");
356-
const targetPath = target.path.replaceAll("\\", "/").replace(/([^/:])\/+$/, "$1");
352+
// Windows paths compare case-insensitively, matching workspaceRelativeFilePath.
353+
const caseInsensitive = isWindowsAbsolutePath(stripSlashPrefixedWindowsDrive(target.path));
354+
const normalize = (value: string) => (caseInsensitive ? value.toLowerCase() : value);
355+
const path = normalize(
356+
(parseMarkdownFileLink(label)?.path ?? splitFilePathPosition(label.trim()).path)
357+
.replaceAll("\\", "/")
358+
.replace(/^\.\//, "")
359+
.replace(/([^/:])\/+$/, "$1"),
360+
);
361+
const targetPath = normalize(target.path.replaceAll("\\", "/").replace(/([^/:])\/+$/, "$1"));
357362
return path === targetPath || targetPath.endsWith(`/${path}`);
358363
}

0 commit comments

Comments
 (0)