Skip to content

Commit a1f9d1c

Browse files
fix(shared): resolve home links from mixed-case Windows paths
1 parent 348f217 commit a1f9d1c

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎packages/shared/src/fileLinks.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ describe("resolvePathLinkTarget", () => {
6666
it.each([
6767
["C:\\Users\\julius\\project", "C:\\Users\\julius\\notes.md:3"],
6868
["C:/Users/julius/project", "C:/Users/julius\\notes.md:3"],
69+
["C:\\users\\alice\\project", "C:\\users\\alice\\notes.md:3"],
70+
["C:/uSeRs/alice/project", "C:/uSeRs/alice\\notes.md:3"],
6971
])("resolves home paths against the Windows cwd %s", (cwd, expected) => {
7072
expect(resolvePathLinkTarget("~/notes.md:3", cwd)).toBe(expected);
7173
});
74+
it("keeps home paths unchanged when no supported home can be inferred", () => {
75+
for (const cwd of ["C:/work/project", "/Home/alice/project", "/users/alice/project"]) {
76+
expect(resolvePathLinkTarget("~/notes.md:3", cwd)).toBe("~/notes.md:3");
77+
}
78+
});
7279
});

‎packages/shared/src/fileLinks.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function inferHomeFromCwd(cwd: string): string | undefined {
8080
return `/home/${posixHome[1]}`;
8181
}
8282

83-
const windowsUser = cwd.match(/^([A-Za-z]:[\\/]Users[\\/][^\\/]+)/);
83+
const windowsUser = cwd.match(/^([A-Za-z]:[\\/]Users[\\/][^\\/]+)/i);
8484
if (windowsUser?.[1]) {
8585
return windowsUser[1];
8686
}

0 commit comments

Comments
 (0)