Skip to content

Commit 65ac7f5

Browse files
heiskrCopilot
andauthored
Fix .md URLs redirecting instead of serving markdown (#60120)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 06f555f commit 65ac7f5

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/shielding/middleware/handle-invalid-paths.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export default function handleInvalidPaths(
8989
return res.redirect(newUrl)
9090
} else if (req.path.endsWith('.md')) {
9191
req.url = req.url.replace(/\.md($|\?)/, '$1')
92+
req.originalUrl = req.originalUrl.replace(/\.md($|\?)/, '$1')
9293
req.headers.accept = 'text/markdown'
9394
return next()
9495
}

src/shielding/tests/shielding.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ describe('index.md and .md suffixes', () => {
7777
{
7878
const res = await get('/en/get-started.md')
7979
// Should not redirect — serves markdown directly (or 404 if page doesn't exist)
80+
expect(res.statusCode).not.toBe(301)
8081
expect(res.statusCode).not.toBe(302)
8182
}
8283
})

0 commit comments

Comments
 (0)