From 00b7866874a5290223e709c79e7c2f96726486d2 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Fri, 29 Nov 2013 11:08:58 -0500 Subject: [PATCH] Fix up issue in node.js' impl of basename --- src/fs.js | 3 ++- src/path.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/fs.js b/src/fs.js index e594a1a..fd342bd 100644 --- a/src/fs.js +++ b/src/fs.js @@ -1721,7 +1721,8 @@ define(function(require) { }; return { - FileSystem: FileSystem + FileSystem: FileSystem, + Path: require('src/path') }; }); diff --git a/src/path.js b/src/path.js index 38eeffa..7c0fbfb 100644 --- a/src/path.js +++ b/src/path.js @@ -67,7 +67,7 @@ define(function() { resolvedAbsolute = false; for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - var path = arguments[i]; + var path = (i >= 0) ? arguments[i] : '/'; // Skip empty and invalid entries if (typeof path !== 'string' || !path) { @@ -182,7 +182,8 @@ define(function() { if (ext && f.substr(-1 * ext.length) === ext) { f = f.substr(0, f.length - ext.length); } - return f; + // NOTE: node.js just does `return f` + return f === "" ? "/" : f; } function extname(path) {