diff options
author | Bert Belder <bertbelder@gmail.com> | 2010-11-30 10:36:25 +0100 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2010-12-20 23:51:27 +0100 |
commit | 9be07f7fe196c574a895e12cc5b372c292edfc9d (patch) | |
tree | fb9af85670aa4f6484c2600cff231935b05045c0 /lib/path.js | |
parent | ad41e778b43608cb0bd58103a5848e94acba58f4 (diff) | |
download | android-node-v8-9be07f7fe196c574a895e12cc5b372c292edfc9d.tar.gz android-node-v8-9be07f7fe196c574a895e12cc5b372c292edfc9d.tar.bz2 android-node-v8-9be07f7fe196c574a895e12cc5b372c292edfc9d.zip |
_Partial_ fix for backslash path separator support in path.js
Needs review & tests
Diffstat (limited to 'lib/path.js')
-rw-r--r-- | lib/path.js | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/path.js b/lib/path.js index fc7f4c3ba6..43461cdc1c 100644 --- a/lib/path.js +++ b/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). |