Skip to content

Commit ef7a088

Browse files
zbinlinFishrock123
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> Conflicts: test/parallel/test-path-parse-format.js
1 parent 795c85b commit ef7a088

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ var winPaths = [
1919
'\\\\?\\UNC\\server\\share'
2020
];
2121

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

7882
checkParseFormat(path.win32, winPaths);
7983
checkParseFormat(path.posix, unixPaths);
84+
checkSpecialCaseParseFormat(path.win32, winSpecialCaseParseTests);
8085
checkErrors(path.win32);
8186
checkErrors(path.posix);
8287
checkFormat(path.win32, winSpecialCaseFormatTests);
@@ -175,6 +180,17 @@ function checkParseFormat(path, paths) {
175180
});
176181
}
177182

183+
function checkSpecialCaseParseFormat(path, testCases) {
184+
testCases.forEach(function(testCase) {
185+
const element = testCase[0];
186+
const expect = testCase[1];
187+
const output = path.parse(element);
188+
Object.keys(expect).forEach(function(key) {
189+
assert.strictEqual(output[key], expect[key]);
190+
});
191+
});
192+
}
193+
178194
function checkFormat(path, testCases) {
179195
testCases.forEach(function(testCase) {
180196
assert.strictEqual(path.format(testCase[0]), testCase[1]);

0 commit comments

Comments
 (0)