Skip to content

Commit 22c08d6

Browse files
committed
fix(web): preserve trailing spaces in file links
1 parent f695cce commit 22c08d6

4 files changed

Lines changed: 25 additions & 7 deletions

File tree

‎apps/web/src/filePathDisplay.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
isWindowsAbsolutePath,
3+
normalizePathCaseForComparison,
34
normalizeProjectPathForComparison,
45
normalizeProjectPathForDispatch,
56
} from "@t3tools/shared/path";
@@ -24,11 +25,11 @@ function stripRelativePrefixes(path: string): string {
2425
}
2526

2627
export function resolveWorkspaceRelativePath(path: string, workspaceRoot: string): string | null {
27-
const normalizedPath = canonicalizeWindowsDrivePath(normalizeProjectPathForDispatch(path));
28+
const normalizedPath = canonicalizeWindowsDrivePath(path);
2829
const normalizedRoot = canonicalizeWindowsDrivePath(
2930
normalizeProjectPathForDispatch(workspaceRoot),
3031
);
31-
const pathForCompare = normalizeProjectPathForComparison(normalizedPath);
32+
const pathForCompare = normalizePathCaseForComparison(normalizedPath);
3233
const rootForCompare = normalizeProjectPathForComparison(normalizedRoot);
3334

3435
if (pathForCompare === rootForCompare) return "";

‎apps/web/src/markdown-links.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ describe("resolveMarkdownFileLinkTarget", () => {
132132
});
133133
});
134134

135+
it("preserves trailing whitespace in encoded workspace file paths", () => {
136+
expect(resolveMarkdownFileLinkMeta("/tmp/repo/file.ts%20", "/tmp/repo")).toMatchObject({
137+
targetPath: "/tmp/repo/file.ts ",
138+
displayPath: "repo/file.ts ",
139+
workspaceRelativePath: "file.ts ",
140+
});
141+
});
142+
135143
it("keeps windows workspace containment case-insensitive", () => {
136144
expect(
137145
resolveMarkdownFileLinkMeta(

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
isUncPath,
55
isWindowsAbsolutePath,
66
isWindowsDrivePath,
7+
normalizePathCaseForComparison,
78
} from "./path.ts";
89

910
describe("path helpers", () => {
@@ -31,4 +32,9 @@ describe("path helpers", () => {
3132
expect(isExplicitRelativePath("..\\repo")).toBe(true);
3233
expect(isExplicitRelativePath("~/repo")).toBe(false);
3334
});
35+
36+
it("normalizes windows path casing without trimming filenames", () => {
37+
expect(normalizePathCaseForComparison("C:/Repo/file.ts ")).toBe("c:\\repo\\file.ts ");
38+
expect(normalizePathCaseForComparison("/repo/file.ts ")).toBe("/repo/file.ts ");
39+
});
3440
});

‎packages/shared/src/path.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ export function normalizeProjectPathForDispatch(value: string): string {
4242
return trimTrailingPathSeparators(value.trim());
4343
}
4444

45-
export function normalizeProjectPathForComparison(value: string): string {
46-
const normalized = normalizeProjectPathForDispatch(value);
47-
if (isWindowsDrivePath(normalized) || isUncPath(normalized)) {
48-
return normalized.replaceAll("/", "\\").toLowerCase();
45+
export function normalizePathCaseForComparison(value: string): string {
46+
if (isWindowsDrivePath(value) || isUncPath(value)) {
47+
return value.replaceAll("/", "\\").toLowerCase();
4948
}
50-
return normalized;
49+
return value;
50+
}
51+
52+
export function normalizeProjectPathForComparison(value: string): string {
53+
return normalizePathCaseForComparison(normalizeProjectPathForDispatch(value));
5154
}

0 commit comments

Comments
 (0)