Skip to content

Commit 4717ea9

Browse files
zbinlinsilverwind
authored andcommitted
path: fix win32 parse()
Fix path.win32.parse("/foo/bar") retuns `{root: '' ...}`(v5.7.0), but not `{root: '/' ...}`(v5.6.0). PR-URL: #5484 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Roman Reiss <me@silverwind.io>
1 parent 3c79bbd commit 4717ea9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,8 @@ const win32 = {
10071007
isAbsolute = true;
10081008

10091009
code = path.charCodeAt(1);
1010+
rootEnd = 1;
10101011
if (code === 47/*/*/ || code === 92/*\*/) {
1011-
rootEnd = 1;
10121012
// Matched double path separator at beginning
10131013
var j = 2;
10141014
var last = j;

test/parallel/test-path-parse-format.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const winPaths = [
2020
'\\\\?\\UNC\\server\\share'
2121
];
2222

23+
const winSpecialCaseParseTests = [
24+
['/foo/bar', {root: '/'}]
25+
];
26+
2327
const winSpecialCaseFormatTests = [
2428
[{dir: 'some\\dir'}, 'some\\dir\\'],
2529
[{base: 'index.html'}, 'index.html'],
@@ -86,6 +90,7 @@ const errors = [
8690

8791
checkParseFormat(path.win32, winPaths);
8892
checkParseFormat(path.posix, unixPaths);
93+
checkSpecialCaseParseFormat(path.win32, winSpecialCaseParseTests);
8994
checkErrors(path.win32);
9095
checkErrors(path.posix);
9196
checkFormat(path.win32, winSpecialCaseFormatTests);
@@ -184,6 +189,17 @@ function checkParseFormat(path, paths) {
184189
});
185190
}
186191

192+
function checkSpecialCaseParseFormat(path, testCases) {
193+
testCases.forEach(function(testCase) {
194+
const element = testCase[0];
195+
const expect = testCase[1];
196+
const output = path.parse(element);
197+
Object.keys(expect).forEach(function(key) {
198+
assert.strictEqual(output[key], expect[key]);
199+
});
200+
});
201+
}
202+
187203
function checkFormat(path, testCases) {
188204
testCases.forEach(function(testCase) {
189205
assert.strictEqual(path.format(testCase[0]), testCase[1]);

0 commit comments

Comments
 (0)