diff --git a/test/static-encode/[...]/a .md b/test/static-encode/[...]/a .md new file mode 100644 index 0000000..96236f8 --- /dev/null +++ b/test/static-encode/[...]/a .md @@ -0,0 +1 @@ +example \ No newline at end of file diff --git a/test/static.test.js b/test/static.test.js index e8b2fd1..8f86e6c 100644 --- a/test/static.test.js +++ b/test/static.test.js @@ -3756,6 +3756,7 @@ t.test( t.end() } ) + t.test( 'converts URL to path', async (t) => { @@ -3803,3 +3804,39 @@ t.test( t.same(response.body, foobarContent) } ) + +t.test( + 'serves files with paths that have characters modified by encodeUri when wildcard is false', + async (t) => { + const aContent = fs.readFileSync(path.join(__dirname, 'static-encode/[...]', 'a .md'), 'utf-8') + + t.plan(4) + const pluginOptions = { + root: url.pathToFileURL(path.join(__dirname, '/static-encode')), + wildcard: false + } + + const fastify = Fastify() + + fastify.register(fastifyStatic, pluginOptions) + const response = await fastify.inject({ + method: 'GET', + url: '[...]/a .md', + headers: { + 'accept-encoding': '*, *' + } + }) + t.equal(response.statusCode, 200) + t.same(response.body, aContent) + + const response2 = await fastify.inject({ + method: 'GET', + url: '%5B...%5D/a%20.md', + headers: { + 'accept-encoding': '*, *' + } + }) + t.equal(response2.statusCode, 200) + t.same(response2.body, aContent) + } +)