mirror of https://github.com/nodejs/node.git
Fix dirname so that dirname('/a/b/') -> '/a', like sh's does.
Before there was this comment: Can't strip trailing slashes since module.js incorrectly thinks dirname('/a/b/') should yield '/a/b' instead of '/a'. But now, such thinking is corrected.pull/5370/head
parent
e0d6f14b22
commit
f0f247d7e5
|
@ -197,7 +197,7 @@ function resolveModulePath(request, parent) {
|
|||
}
|
||||
|
||||
var parentIdPath = path.dirname(parent.id +
|
||||
(path.basename(parent.filename).match(new RegExp('^index\\.(' + exts.join('|') + ')$')) ? "/" : ""));
|
||||
(path.basename(parent.filename).match(new RegExp('^index\\.(' + exts.join('|') + ')$')) ? "/." : ""));
|
||||
id = path.join(parentIdPath, request);
|
||||
// make sure require('./path') and require('path') get distinct ids, even
|
||||
// when called from the toplevel js file
|
||||
|
|
|
@ -38,11 +38,9 @@ exports.normalize = function (path, keepBlanks) {
|
|||
};
|
||||
|
||||
exports.dirname = function (path) {
|
||||
// Can't strip trailing slashes since module.js incorrectly thinks
|
||||
// dirname('/a/b/') should yield '/a/b' instead of '/a'.
|
||||
// if (path.length > 1 && '/' === path[path.length-1]) {
|
||||
// path = path.replace(/\/+$/, '');
|
||||
// }
|
||||
if (path.length > 1 && '/' === path[path.length-1]) {
|
||||
path = path.replace(/\/+$/, '');
|
||||
}
|
||||
var lastSlash = path.lastIndexOf('/');
|
||||
switch (lastSlash) {
|
||||
case -1:
|
||||
|
|
|
@ -8,6 +8,7 @@ assert.equal(path.basename(f), "test-path.js");
|
|||
assert.equal(path.basename(f, ".js"), "test-path");
|
||||
assert.equal(path.extname(f), ".js");
|
||||
assert.equal(path.dirname(f).substr(-11), "test/simple");
|
||||
assert.equal(path.dirname("/a/b/"), "/a");
|
||||
assert.equal(path.dirname("/a/b"), "/a");
|
||||
assert.equal(path.dirname("/a"), "/");
|
||||
assert.equal(path.dirname("/"), "/");
|
||||
|
|
Loading…
Reference in New Issue