path: fix slice OOB in trim
authorLucio M. Tato <luciotato@gmail.com>
Sat, 2 Aug 2014 05:33:35 +0000 (02:33 -0300)
committerTrevor Norris <trev.norris@gmail.com>
Sat, 2 Aug 2014 07:19:20 +0000 (00:19 -0700)
Internal function trim(arr). 2nd parameter of slice() should be slice's
end index (not included). Because of function normalize() (called before
trim()), "start" is always zero so the bug -for now- has no effect, but
its a bug waiting to happen.

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
lib/path.js

index 768c4c1..04187aa 100644 (file)
@@ -269,7 +269,7 @@ if (isWindows) {
       }
 
       if (start > end) return [];
-      return arr.slice(start, end - start + 1);
+      return arr.slice(start, end + 1);
     }
 
     var toParts = trim(to.split('\\'));
@@ -413,7 +413,7 @@ if (isWindows) {
       }
 
       if (start > end) return [];
-      return arr.slice(start, end - start + 1);
+      return arr.slice(start, end + 1);
     }
 
     var fromParts = trim(from.split('/'));