diff options
author | Andreas Madsen <amwebdk@gmail.com> | 2013-01-08 21:22:04 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-01-11 05:58:37 +0400 |
commit | bb1c03989f8702e06072e6d9228b52661bf00ace (patch) | |
tree | 25c56928dee2659b3a482285bf422d6439fb1aa0 /lib/path.js | |
parent | b916774255940c721df882b5b8ab63934891df99 (diff) |
path: fix bugs related to paths with trailing slashes
Diffstat (limited to 'lib/path.js')
-rw-r--r-- | lib/path.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/path.js b/lib/path.js index 0b24de299fc..980348e7d11 100644 --- a/lib/path.js +++ b/lib/path.js @@ -290,7 +290,17 @@ if (isWindows) { // 'root' is just a slash, or nothing. var splitPathRe = /^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/; + var trailingSlash = /\/+$/; var splitPath = function(filename) { + + // removes trailing slashes before spliting the path + var tail = trailingSlash.exec(filename); + if (tail) { + if (tail.index === 0) return ['/', '', '', '']; + + filename = filename.slice(0, tail.index); + } + var result = splitPathRe.exec(filename); return [result[1] || '', result[2] || '', result[3] || '', result[4] || '']; }; |