From ede9189b6c586cd4697e0ffb16671515fdefecde Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Sun, 28 Mar 2021 17:08:36 -0700 Subject: [PATCH] chore(sirv): add test for filename with space (#102) * Add test case around handling file names with spaces This is specifically for sveltejs/kit#740 to assert that sirv is working as expected. * Apply suggestions from code review Co-authored-by: Luke Edwards --- tests/public/with space.txt | 1 + tests/sirv.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/public/with space.txt diff --git a/tests/public/with space.txt b/tests/public/with space.txt new file mode 100644 index 0000000..dc5f87e --- /dev/null +++ b/tests/public/with space.txt @@ -0,0 +1 @@ +with space.txt diff --git a/tests/sirv.js b/tests/sirv.js index fb25f38..20fa567 100644 --- a/tests/sirv.js +++ b/tests/sirv.js @@ -123,6 +123,32 @@ encode('should work when the request path contains encoded characters :: prod', } }); +encode(`should work when the request path contains space encoded :: dev`, async () => { + let server = utils.http({ dev: true }); + + try { + let res = await server.send('GET', '/with%20space.txt'); + assert.is(res.headers['content-type'], 'text/plain'); + assert.is(res.data, 'with space.txt\n'); + assert.is(res.statusCode, 200); + } finally { + server.close(); + } +}); + +encode(`should work when the request path contains space encoded :: prod`, async () => { + let server = utils.http({ dev: false }); + + try { + let res = await server.send('GET', '/with%20space.txt'); + assert.is(res.headers['content-type'], 'text/plain'); + assert.is(res.data, 'with space.txt\n'); + assert.is(res.statusCode, 200); + } finally { + server.close(); + } +}); + encode.run(); // ---