Browse Source

_Partial_ fix for backslash path separator support in path.js

Needs review & tests
v0.7.4-release
Bert Belder 14 years ago
parent
commit
9be07f7fe1
  1. 12
      lib/path.js

12
lib/path.js

@ -17,8 +17,8 @@ exports.join = function() {
exports.split = function(path, keepBlanks) {
// split based on /, but only if that / is not at the start or end.
return exports.normalizeArray(path.split(/^|\/(?!$)/), keepBlanks);
// split based on / and \, but only if that / is not at the start or end.
return exports.normalizeArray(path.split(/^|[\\\/](?!$)/), keepBlanks);
};
@ -46,7 +46,7 @@ function cleanArray(parts, keepBlanks) {
return parts.filter(function(p) { return validPathPart(p, keepBlanks) })
.join('/')
.split(/^|\/(?!$)/);
.split(/^|[\\\/](?!$)/);
}
@ -112,10 +112,10 @@ exports.normalize = function(path, keepBlanks) {
exports.dirname = function(path) {
if (path.length > 1 && '/' === path[path.length - 1]) {
if (path.length > 1 && '\\/'.indexOf(path[path.length-1]) != -1) {
path = path.replace(/\/+$/, '');
}
var lastSlash = path.lastIndexOf('/');
var lastSlash = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
switch (lastSlash) {
case -1:
return '.';
@ -138,7 +138,7 @@ exports.basename = function(path, ext) {
exports.extname = function(path) {
var dot = path.lastIndexOf('.'),
slash = path.lastIndexOf('/');
slash = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
// The last dot must be in the last path component, and it (the last dot) must
// not start the last path component (i.e. be a dot that signifies a hidden
// file in UNIX).

Loading…
Cancel
Save