From 7da326b86ea47295c83a5ee921f5fa93795397ea Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Mon, 26 Oct 2026 14:55:47 +0100 Subject: [PATCH] fix: keep the server's path in the fallback CalDAV address --- .../calendar-management-settings.test.tsx | 18 ++++++++++++++++++ .../settings/calendar-management-settings.tsx | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/components/settings/__tests__/calendar-management-settings.test.tsx b/components/settings/__tests__/calendar-management-settings.test.tsx index 850bb4d76..af1f4d79d 100644 --- a/components/settings/__tests__/calendar-management-settings.test.tsx +++ b/components/settings/__tests__/calendar-management-settings.test.tsx @@ -54,3 +54,21 @@ describe('CalendarManagementSettings rename', () => { expect(updateCalendar.mock.calls[0].slice(1)).toEqual(['cal', { name: 'Home', color: CALENDAR_COLORS[0] }]); }); }); + +// When discovery fails, the CalDAV address falls back to the server's +// well-known path. Built from the origin, it dropped the path of a server +// mounted below the root (https://host/stalwart). +describe('CalendarManagementSettings CalDAV fallback address', () => { + it('keeps the path of a server mounted below the root', async () => { + vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response('{}', { status: 502 })); + useAuthStore.setState({ + client: { getAccountId: () => 'acct-1' }, serverUrl: 'https://host.example/stalwart/', username: 'alice@example.com', + } as never); + useCalendarStore.setState({ calendars: [appleColored], icalSubscriptions: [], updateCalendar: vi.fn() } as never); + + render(); + + expect(await screen.findByText('https://host.example/stalwart/.well-known/caldav')).toBeInTheDocument(); + vi.restoreAllMocks(); + }); +}); diff --git a/components/settings/calendar-management-settings.tsx b/components/settings/calendar-management-settings.tsx index 1e3ba8082..487e4dc2d 100644 --- a/components/settings/calendar-management-settings.tsx +++ b/components/settings/calendar-management-settings.tsx @@ -342,7 +342,8 @@ export function CalendarManagementSettings() { setDiscoveredCalDavUrls(next); }) .catch(() => { - const fallbackWellKnown = new URL('/.well-known/caldav', serverUrl).toString(); + // Below the server address, which may carry a path (https://host/stalwart). + const fallbackWellKnown = `${serverUrl.replace(/\/+$/, '')}/.well-known/caldav`; setDiscoveredCalDavUrls({}); setWellKnownCalDavUrl(fallbackWellKnown); });