Skip to content

Commit 8ccb3af

Browse files
Copilotabernier
andcommitted
Add test for URL-encoded path decoding and double-slash prevention
Co-authored-by: abernier <76580+abernier@users.noreply.github.com>
1 parent 778d75b commit 8ccb3af

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/app/api/[transport]/route.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,25 @@ Content with &lt;special&gt; characters &amp; symbols.
363363
expect(page.length).toBe(1)
364364
})
365365

366+
it('should decode URL-encoded paths correctly', async () => {
367+
const cheerio = await import('cheerio')
368+
const $ = cheerio.load(mockLlmsFullTxt, { xmlMode: true })
369+
370+
// Simulate URL-encoded path as it comes from MCP SDK
371+
// Path /api/hooks/use-frame is encoded as %2Fapi%2Fhooks%2Fuse-frame
372+
const urlEncodedPath = '%2Fapi%2Fhooks%2Fuse-frame'
373+
const decodedPath = decodeURIComponent(urlEncodedPath)
374+
375+
// After decoding, path already has leading slash, don't add another
376+
const searchPath = decodedPath.startsWith('/') ? decodedPath : `/${decodedPath}`
377+
378+
expect(searchPath).toBe('/api/hooks/use-frame') // Should NOT be //api/hooks/use-frame
379+
380+
const page = $('page').filter((_, el) => $(el).attr('path') === searchPath)
381+
expect(page.length).toBe(1)
382+
expect(page.attr('title')).toBe('useFrame Hook')
383+
})
384+
366385
it('should format resource response correctly', async () => {
367386
const cheerio = await import('cheerio')
368387
const $ = cheerio.load(mockLlmsFullTxt, { xmlMode: true })

0 commit comments

Comments
 (0)