Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/core/src/stores/sync-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe("useSyncStore", () => {
});
});

it("saves custom WebDAV remote root and trims nested path", async () => {
it("saves custom WebDAV remote root and preserves path casing", async () => {
mockPlatformService.kvGetItem.mockResolvedValue("saved-secret");

await useSyncStore
Expand All @@ -232,7 +232,7 @@ describe("useSyncStore", () => {
"alice",
"password",
false,
" /apps//readany-sync/ ",
" /Apps//ReadAny-Sync/ ",
);

const savedConfigCall = mockPlatformService.kvSetItem.mock.calls.find(
Expand All @@ -243,7 +243,7 @@ describe("useSyncStore", () => {
type: "webdav",
url: "https://dav.example.com/root",
username: "alice",
remoteRoot: "apps/readany-sync",
remoteRoot: "Apps/ReadAny-Sync",
});
});

Expand Down
32 changes: 32 additions & 0 deletions packages/core/src/sync/webdav-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,38 @@ describe("WebDavClient PROPFIND parsing", () => {
expect(calls.map((call) => call.method)).toEqual(["PROPFIND"]);
expect(calls.map((call) => call.url)).toEqual(["https://dav.example.com/dav/readany/sync/"]);
});

it("preserves remote root path casing while normalizing slashes", () => {
expect(sanitizeWebDavRemoteRoot(" /Apps//ReadAny-Sync/ ")).toBe("Apps/ReadAny-Sync");
});

it("percent-encodes non-ASCII WebDAV request paths without adding path headers", async () => {
const calls: Array<{ url: string; headers: Record<string, string> }> = [];
installFetchStub((url, options) => {
calls.push({
url,
headers: (options?.headers ?? {}) as Record<string, string>,
});
return new Response(new Uint8Array([1, 2, 3]), { status: 200 });
});

const client = new WebDavClient("https://dav.example.com/dav", "alice", "secret");
const path =
"/ReadAnySync/data/books/这里是,终末停滞委员会。 [第一卷]/姉の彼女にキスをした.epub";
await client.get(path);

const expectedPath = path
.split("/")
.map((segment) => encodeURIComponent(segment))
.join("/");
expect(calls[0]?.url).toBe(`https://dav.example.com/dav${expectedPath}`);
expect(Object.keys(calls[0]?.headers ?? {})).toEqual(["Authorization"]);
expect(
Object.values(calls[0]?.headers ?? {}).every((value) =>
Array.from(value).every((char) => char.charCodeAt(0) <= 0x7f),
),
).toBe(true);
});
});

describe("sanitizeWebDavRemoteRoot", () => {
Expand Down