diff --git a/src/node.js b/src/node.js index c6c3a6a39f..e9a1e77b93 100644 --- a/src/node.js +++ b/src/node.js @@ -670,28 +670,36 @@ var pathModule = createInternalModule("path", function (exports) { return exports.normalize(Array.prototype.join.call(arguments, "/")); }; - exports.normalizeArray = function (parts) { - var directories = []; - for (var i = 0; i < parts.length; i++) { + exports.normalizeArray = function (parts, keepBlanks) { + var directories = [], prev; + for (var i = 0, l = parts.length - 1; i <= l; i++) { var directory = parts[i]; - if (directory === "." || (directory === "" && directories.length)) { - continue; - } + + // if it's blank, but it's not the first thing, and not the last thing, skip it. + if (directory === "" && i !== 0 && i !== l && !keepBlanks) continue; + + // if it's a dot, and there was some previous dir already, then skip it. + if (directory === "." && prev) continue; + if ( directory === ".." && directories.length - && directories[directories.length - 1] != '..' + && prev != '..' + && prev != '' ) { directories.pop(); + prev = directories.slice(-1)[0] } else { + if (prev === ".") directories.pop(); directories.push(directory); + prev = directory; } } return directories; }; - exports.normalize = function (path) { - return exports.normalizeArray(path.split("/")).join("/"); + exports.normalize = function (path, keepBlanks) { + return exports.normalizeArray(path.split("/"), keepBlanks).join("/"); }; exports.dirname = function (path) {