Skip to content

utils: use external pathIsAbsolute #2620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var deprecate = require('depd')('express');
var mime = require('send').mime;
var basename = require('path').basename;
var etag = require('etag');
var pathIsAbsolute = require('path-is-absolute');
var proxyaddr = require('proxy-addr');
var qs = require('qs');
var querystring = require('querystring');
Expand Down Expand Up @@ -62,11 +63,7 @@ exports.wetag = function wetag(body, encoding){
* @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
};
exports.isAbsolute = pathIsAbsolute;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into this, it's unfortunate that since path-is-absolute is actually exporting a platform-specific absolute function, this check is not actually backwards-compatible. Yes, path-is-absolute is doing the "better thing", but I fear what this could break. The problem really comes down to Windows: if people are giving the path '/some/layout/index.hbs', our views currently thinks it's absolute and we do not prepend the root, and so on Windows, it'll map to 'C:\\some\\layout\\index.hbs', where the drive is dependent on process.cwd().

Thoughts?

We should definately move exclusively to this module in 5.x, but in 4.x, we can probably just do return pathIsAbsolute.posix(path) || pathIsAbsolute.win32(path).


/**
* Flatten the given `arr`.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"methods": "~1.1.1",
"on-finished": "~2.2.0",
"parseurl": "~1.3.0",
"path-is-absolute": "~1.0.0",
"path-to-regexp": "0.1.3",
"proxy-addr": "~1.0.7",
"qs": "2.4.1",
Expand Down
16 changes: 0 additions & 16 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,6 @@ describe('utils.wetag(body, encoding)', function(){
})
})

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'));
})
})

describe('utils.flatten(arr)', function(){
it('should flatten an array', function(){
var arr = ['one', ['two', ['three', 'four'], 'five']];
Expand Down