Skip to content

Commit

Permalink
fix(exposeFolder): handle URI encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbonnet committed Dec 4, 2020
1 parent 532347b commit e1cc0e3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/exposeFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { getAcceptedEncodingList } from './getAcceptedEncodingList'
import { isChildPath } from './isChildPath'
import { COMPRESSIBLE_CONTENT_TYPES } from './COMPRESSIBLE_CONTENT_TYPES'

const { decodeURI } = global

export function exposeFolder({
path: folderPath,
index,
Expand All @@ -19,7 +21,7 @@ export function exposeFolder({
const pathname = normalize(
join(
folderPath,
request.pathname == null ? request.url : request.pathname,
decodeURI(request.pathname == null ? request.url : request.pathname),
),
)
if (!isChildPath(folderPath, pathname)) {
Expand Down
4 changes: 4 additions & 0 deletions src/tests/exposeFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ test('exposes folder', async (assert) => {
},
})
assert.snapshot(await response4.toString(), 'returns not found')
const response5 = await ask(handler, {
url: '/Example%20Text.txt',
})
assert.snapshot(await response5.toString(), 'returns txt file')
})
1 change: 1 addition & 0 deletions src/tests/fixtures/files/Example Text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is an example.
14 changes: 14 additions & 0 deletions src/tests/snapshots/exposeFolder.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,17 @@ Generated by [AVA](https://avajs.dev).
0␍␊
␍␊
`

> returns txt file
`HTTP/1.1 200 OK␍␊
Cache-Control: public, max-age=31536000␍␊
Content-Type: text/plain␍␊
Connection: keep-alive␍␊
Transfer-Encoding: chunked␍␊
␍␊
13␍␊
This is an example.␍␊
0␍␊
␍␊
`
Binary file modified src/tests/snapshots/exposeFolder.js.snap
Binary file not shown.
26 changes: 26 additions & 0 deletions src/tests/snapshots/writeCompressibleBody.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Snapshot report for `src/tests/writeCompressibleBody.js`

The actual snapshot is saved in `writeCompressibleBody.js.snap`.

Generated by [AVA](https://avajs.dev).

## writes body in br

> matches
`HTTP/1.1 200 OK␍␊
content-encoding: br␍␊
Connection: keep-alive␍␊
Transfer-Encoding: chunked␍␊
␍␊
eDQo=GwwA+CUAShBDioV6/gM=DQo=MA0KDQo=`

## writes uncompressed body if no compatible acceptable encoding found

> matches
`HTTP/1.1 200 OK␍␊
Content-Length: 13␍␊
Connection: keep-alive␍␊
␍␊
Response body`
Binary file added src/tests/snapshots/writeCompressibleBody.js.snap
Binary file not shown.

0 comments on commit e1cc0e3

Please sign in to comment.