Skip to content

Commit

Permalink
path.js: correct three harmless .length typos
Browse files Browse the repository at this point in the history
lib/path.js routines normalizeArray() and resolve() have for loops that
count down from end of an array.  The loop indexes are initialized using
"array.length" rather than "array.length-1".  The initial array element
accessed is always beyond the end of array and the value is 'undefined'.
Strangely, code exists that acts to ignore undefined values so that the
typos are unnoticeable.

Existing tests emit no errors either before or after changing to "length-1".
Tests _do_ start failing at "length-2". (Actually it is node that starts
to fail at "length-2" - that's a valid enough test...)
  • Loading branch information
tshinnic authored and bnoordhuis committed Aug 14, 2011
1 parent bfc2982 commit a5d90c4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var isWindows = process.platform === 'win32';
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length; i >= 0; i--) {
for (var i = parts.length-1; i >= 0; i--) {
var last = parts[i];
if (last == '.') {
parts.splice(i, 1);
Expand Down Expand Up @@ -72,7 +72,7 @@ if (isWindows) {
resolvedTail = '',
resolvedAbsolute = false;

for (var i = arguments.length; i >= -1; i--) {
for (var i = arguments.length-1; i >= -1; i--) {
var path = (i >= 0) ? arguments[i] : process.cwd();

// Skip empty and invalid entries
Expand Down Expand Up @@ -255,7 +255,7 @@ if (isWindows) {
var resolvedPath = '',
resolvedAbsolute = false;

for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
for (var i = arguments.length-1; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0) ? arguments[i] : process.cwd();

// Skip empty and invalid entries
Expand Down

0 comments on commit a5d90c4

Please sign in to comment.