diff --git a/.changeset/blue-ideas-design.md b/.changeset/blue-ideas-design.md new file mode 100644 index 000000000..c7453d0d6 --- /dev/null +++ b/.changeset/blue-ideas-design.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Fix 404 when accessing rss.xml for the root page. diff --git a/packages/gitbook/src/app/utils.ts b/packages/gitbook/src/app/utils.ts index 1118c4fc2..ff6fd6ffc 100644 --- a/packages/gitbook/src/app/utils.ts +++ b/packages/gitbook/src/app/utils.ts @@ -83,6 +83,11 @@ export function getPagePathFromParams(params: RouteParams) { // If decoding the param fails, return a 404 instead of crashing try { const decoded = decodeURIComponent(params.pagePath); + + // For the root page, we encode '/' to avoid an empty param being passed. + if (decoded === '/') { + return ''; + } return decoded; } catch (error) { console.error( diff --git a/packages/gitbook/tests/rss.test.ts b/packages/gitbook/tests/rss.test.ts index 580c7fd43..3b50dedc2 100644 --- a/packages/gitbook/tests/rss.test.ts +++ b/packages/gitbook/tests/rss.test.ts @@ -19,4 +19,12 @@ it('should not expose a RSS feed for a page without updates', async () => { ); const response = await fetch(feedURL); expect(response.status).toBe(404); + expect(await response.text()).toBe('No updates found in page'); +}); + +it('should not expose a RSS feed for a page without updates (root page)', async () => { + const feedURL = getContentTestURL('https://gitbook.gitbook.io/test-gitbook-open/rss.xml'); + const response = await fetch(feedURL); + expect(response.status).toBe(404); + expect(await response.text()).toBe('No updates found in page'); });