Skip to content

Commit

Permalink
Merge 51248d2 into f858b06
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Oct 23, 2015
2 parents f858b06 + 51248d2 commit 5a8a02b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var normalize = path.normalize;
var basename = path.basename;
var extname = path.extname;
var resolve = path.resolve;
var parse = path.parse;
var sep = path.sep;
var fs = require('mz/fs');
var co = require('co');

Expand Down Expand Up @@ -41,7 +43,7 @@ function send(ctx, path, opts) {
debug('send "%s" %j', path, opts);
var root = opts.root ? normalize(resolve(opts.root)) : '';
var trailingSlash = '/' == path[path.length - 1];
path = path[0] == '/' ? path.slice(1) : path;
path = path.substr(parse(path).root.length);
var index = opts.index;
var maxage = opts.maxage || opts.maxAge || 0;
var hidden = opts.hidden || false;
Expand Down Expand Up @@ -108,7 +110,7 @@ function send(ctx, path, opts) {
*/

function isHidden(root, path) {
path = path.substr(root.length).split('/');
path = path.substr(root.length).split(sep);
for(var i = 0; i < path.length; i++) {
if(path[i][0] === '.') return true;
}
Expand Down
7 changes: 4 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

var request = require('supertest');
var send = require('..');
var path = require('path');
var koa = require('koa');
var assert = require('assert');

Expand Down Expand Up @@ -281,7 +282,7 @@ describe('send(ctx, file)', function(){
app.use(function *(){
var p = '/test/fixtures/user.json';
var sent = yield send(this, p);
assert.equal(sent, __dirname + '/fixtures/user.json');
assert.equal(sent, path.resolve(__dirname + '/fixtures/user.json'));
});

request(app.listen())
Expand Down Expand Up @@ -358,7 +359,7 @@ describe('send(ctx, file)', function(){
app.use(function *(){
var p = '/test/fixtures/user.json';
var sent = yield send(this, p, { maxage: 5000 });
assert.equal(sent, __dirname + '/fixtures/user.json');
assert.equal(sent, path.resolve(__dirname + '/fixtures/user.json'));
});

request(app.listen())
Expand All @@ -373,7 +374,7 @@ describe('send(ctx, file)', function(){
app.use(function *(){
var p = '/test/fixtures/user.json';
var sent = yield send(this, p, { maxage: 1234 });
assert.equal(sent, __dirname + '/fixtures/user.json');
assert.equal(sent, path.resolve(__dirname + '/fixtures/user.json'));
});

request(app.listen())
Expand Down

0 comments on commit 5a8a02b

Please sign in to comment.