Skip to content

Commit c5afc41

Browse files
9point6haoxin
authored and
haoxin
committedDec 14, 2017
Fix issue with dots in path when using extensions array (#92)
* Fix issue with dots in path when using extensions array * Add missing fixture
1 parent 0910621 commit c5afc41

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async function send (ctx, path, opts = {}) {
8484
encodingExt = '.gz'
8585
}
8686

87-
if (extensions && !/\..*$/.exec(path)) {
87+
if (extensions && !/\.[^/]*$/.exec(path)) {
8888
const list = [].concat(extensions)
8989
for (let i = 0; i < list.length; i++) {
9090
let ext = list[i]

‎test/fixtures/some.path/index.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"foo": 123,
3+
"bar": 456
4+
}

‎test/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,20 @@ describe('send(ctx, file)', function () {
683683
.expect(200, done)
684684
})
685685
})
686+
687+
describe('when trying to get a file without extension with matching .extensions sufficed with other dots in path', function () {
688+
it('should 200', function (done) {
689+
const app = new Koa()
690+
691+
app.use(async (ctx) => {
692+
await send(ctx, 'test/fixtures/some.path/index', { extensions: ['json'] })
693+
})
694+
695+
request(app.listen())
696+
.get('/')
697+
.expect(200, done)
698+
})
699+
})
686700
})
687701

688702
it('should set the Content-Type', function (done) {

0 commit comments

Comments
 (0)
Please sign in to comment.