diff options
author | Bert Belder <bertbelder@gmail.com> | 2013-01-11 21:42:46 +0400 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2013-01-11 21:50:09 +0400 |
commit | 6a91eab0970a87431743c79ecb8e3efaed1796d9 (patch) | |
tree | 666ee877f135af3cfcc538eda7bf5c21783d18dd /lib/path.js | |
parent | b509ae67b794898ff5a2249cf86c7c298e2f3831 (diff) |
path: make basename and extname ignore trailing slashes
Fixes #4536
Diffstat (limited to 'lib/path.js')
-rw-r--r-- | lib/path.js | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/path.js b/lib/path.js index 0b24de299fc..7970ed130b5 100644 --- a/lib/path.js +++ b/lib/path.js @@ -63,7 +63,7 @@ if (isWindows) { // Regex to split the tail part of the above into [*, dir, basename, ext] var splitTailRe = - /^([\s\S]+[\\\/](?!$)|[\\\/])?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/\\]*)?)$/; + /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/; // Function to split a filename into [root, dir, basename, ext] // windows version @@ -74,9 +74,9 @@ if (isWindows) { tail = result[3] || ''; // Split the tail into dir, basename and extension var result2 = splitTailRe.exec(tail), - dir = result2[1] || '', - basename = result2[2] || '', - ext = result2[3] || ''; + dir = result2[1], + basename = result2[2], + ext = result2[3]; return [device, dir, basename, ext]; }; @@ -289,10 +289,9 @@ if (isWindows) { // Split a filename into [root, dir, basename, ext], unix version // 'root' is just a slash, or nothing. var splitPathRe = - /^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/; + /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; var splitPath = function(filename) { - var result = splitPathRe.exec(filename); - return [result[1] || '', result[2] || '', result[3] || '', result[4] || '']; + return splitPathRe.exec(filename).slice(1); }; // path.resolve([from ...], to) |