Skip to content

Commit

Permalink
Use path-is-absolute module for absolute path detection
Browse files Browse the repository at this point in the history
closes #2620
  • Loading branch information
Fishrock123 authored and dougwilson committed Jul 7, 2015
1 parent cec5780 commit 694869d
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 32 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This incorporates all changes after 4.10.1 up to 4.13.1.
* change:
- The leading `:` character in `name` for `app.param(name, fn)` is no longer removed
- Use `router` module for routing
- Use `path-is-absolute` module for absolute path detection

5.0.0-alpha.1 / 2014-11-06
==========================
Expand Down
4 changes: 2 additions & 2 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ var contentDisposition = require('content-disposition');
var deprecate = require('depd')('express');
var escapeHtml = require('escape-html');
var http = require('http');
var isAbsolute = require('./utils').isAbsolute;
var onFinished = require('on-finished');
var path = require('path');
var pathIsAbsolute = require('path-is-absolute');
var merge = require('utils-merge');
var sign = require('cookie-signature').sign;
var normalizeType = require('./utils').normalizeType;
Expand Down Expand Up @@ -369,7 +369,7 @@ res.sendFile = function sendFile(path, options, callback) {
opts = {};
}

if (!opts.root && !isAbsolute(path)) {
if (!opts.root && !pathIsAbsolute(path)) {
throw new TypeError('path must be absolute or specify root to res.sendFile');
}

Expand Down
14 changes: 0 additions & 14 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ exports.wetag = function wetag(body, encoding){
return etag(buf, {weak: true});
};

/**
* Check if `path` looks absolute.
*
* @param {String} path
* @return {Boolean}
* @api private
*/

exports.isAbsolute = function(path){
if ('/' == path[0]) return true;
if (':' == path[1] && '\\' == path[2]) return true;
if ('\\\\' == path.substring(0, 2)) return true; // Microsoft Azure absolute path
};

/**
* Normalize the given `type`, for example "html" becomes "text/html".
*
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"methods": "~1.1.1",
"on-finished": "~2.3.0",
"parseurl": "~1.3.0",
"path-is-absolute": "1.0.0",
"path-to-regexp": "0.1.6",
"proxy-addr": "~1.0.8",
"qs": "4.0.0",
Expand Down
16 changes: 0 additions & 16 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,3 @@ describe('utils.wetag(body, encoding)', function(){
.should.eql('W/"0-1B2M2Y8AsgTpgAmY7PhCfg"');
})
})

describe('utils.isAbsolute()', function(){
it('should support windows', function(){
assert(utils.isAbsolute('c:\\'));
assert(!utils.isAbsolute(':\\'));
})

it('should support windows unc', function(){
assert(utils.isAbsolute('\\\\foo\\bar'))
})

it('should support unices', function(){
assert(utils.isAbsolute('/foo/bar'));
assert(!utils.isAbsolute('foo/bar'));
})
})

0 comments on commit 694869d

Please sign in to comment.