TypeScript
fix(shared): match Windows home paths case-insensitively in file links (#19627)
Jesse van Dijk0a712f0cdc56
diff --git a/packages/shared/src/fileLinks.test.ts b/packages/shared/src/fileLinks.test.tsindex 7d07826089f..dce5d9ce7ce 100644--- a/packages/shared/src/fileLinks.test.ts+++ b/packages/shared/src/fileLinks.test.ts@@ -66,7 +66,14 @@ describe("resolvePathLinkTarget", () => {it.each([["C:\\Users\\julius\\project", "C:\\Users\\julius\\notes.md:3"],["C:/Users/julius/project", "C:/Users/julius\\notes.md:3"],+ ["C:\\users\\alice\\project", "C:\\users\\alice\\notes.md:3"],+ ["C:/uSeRs/alice/project", "C:/uSeRs/alice\\notes.md:3"],])("resolves home paths against the Windows cwd %s", (cwd, expected) => {expect(resolvePathLinkTarget("~/notes.md:3", cwd)).toBe(expected);});+ it("keeps home paths unchanged when no supported home can be inferred", () => {+ for (const cwd of ["C:/work/project", "/Home/alice/project", "/users/alice/project"]) {+ expect(resolvePathLinkTarget("~/notes.md:3", cwd)).toBe("~/notes.md:3");+ }+ });});diff --git a/packages/shared/src/fileLinks.ts b/packages/shared/src/fileLinks.tsindex 65328be0ae6..72c7c7bec04 100644--- a/packages/shared/src/fileLinks.ts+++ b/packages/shared/src/fileLinks.ts@@ -80,7 +80,7 @@ function inferHomeFromCwd(cwd: string): string | undefined {return `/home/${posixHome[1]}`;}- const windowsUser = cwd.match(/^([A-Za-z]:[\\/]Users[\\/][^\\/]+)/);+ const windowsUser = cwd.match(/^([A-Za-z]:[\\/]Users[\\/][^\\/]+)/i);if (windowsUser?.[1]) {return windowsUser[1];}