Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

fix: getRelativePath must compare Windows drive-letter/UNC paths case-insensitively

Andrew Chena3b08ac49741
diff --git a/src/lib/path-utils.test.ts b/src/lib/path-utils.test.ts
index c447fa0c..0b85145e 100644
--- a/src/lib/path-utils.test.ts
+++ b/src/lib/path-utils.test.ts
@@ -116,6 +116,20 @@ describe("getRelativePath", () => {
// The impl adds '/' to base for matching, so this is handled.
expect(getRelativePath("/projector/a", "/project")).toBe("/projector/a")
})
+
+ it("matches Windows drive-letter paths case-insensitively", () => {
+ expect(getRelativePath("c:/users/me/inbox/sub/report.pdf", "C:/Users/Me/Inbox")).toBe(
+ "sub/report.pdf",
+ )
+ })
+
+ it("matches Windows UNC paths case-insensitively", () => {
+ expect(getRelativePath("//server/SHARE/sub/file.md", "//SERVER/share")).toBe("sub/file.md")
+ })
+
+ it("keeps Unix paths case-sensitive", () => {
+ expect(getRelativePath("/Project/wiki/note.md", "/project")).toBe("/Project/wiki/note.md")
+ })
})
describe("isAbsolutePath", () => {
diff --git a/src/lib/path-utils.ts b/src/lib/path-utils.ts
index 758e940d..c1e5c7ae 100644
--- a/src/lib/path-utils.ts
+++ b/src/lib/path-utils.ts
@@ -33,13 +33,23 @@ export function getFileStem(p: string): string {
return lastDot > 0 ? name.slice(0, lastDot) : name
}
+// Windows drive-letter and UNC paths are case-insensitive; fold them for
+// comparison purposes only (never for the paths actually returned/written).
+function caseFoldPath(normalized: string): string {
+ return /^[A-Za-z]:\//.test(normalized) || normalized.startsWith("//")
+ ? normalized.toLowerCase()
+ : normalized
+}
+
/**
* Get relative path from base.
*/
export function getRelativePath(fullPath: string, basePath: string): string {
const normalFull = normalizePath(fullPath)
const normalBase = normalizePath(basePath).replace(/\/$/, "")
- if (normalFull.startsWith(normalBase + "/")) {
+ const fullKey = caseFoldPath(normalFull)
+ const baseKey = caseFoldPath(normalBase)
+ if (fullKey.startsWith(baseKey + "/")) {
return normalFull.slice(normalBase.length + 1)
}
return normalFull