Skip to content

Commit

Permalink
path: fix win32 parse()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
zbinlin authored and silverwind committed Feb 29, 2016
1 parent 3c79bbd commit 4717ea9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,8 @@ const win32 = {
isAbsolute = true;

code = path.charCodeAt(1);
rootEnd = 1;
if (code === 47/*/*/ || code === 92/*\*/) {
rootEnd = 1;
// Matched double path separator at beginning
var j = 2;
var last = j;
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-path-parse-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const winPaths = [
'\\\\?\\UNC\\server\\share'
];

const winSpecialCaseParseTests = [
['/foo/bar', {root: '/'}]
];

const winSpecialCaseFormatTests = [
[{dir: 'some\\dir'}, 'some\\dir\\'],
[{base: 'index.html'}, 'index.html'],
Expand Down Expand Up @@ -86,6 +90,7 @@ const errors = [

checkParseFormat(path.win32, winPaths);
checkParseFormat(path.posix, unixPaths);
checkSpecialCaseParseFormat(path.win32, winSpecialCaseParseTests);
checkErrors(path.win32);
checkErrors(path.posix);
checkFormat(path.win32, winSpecialCaseFormatTests);
Expand Down Expand Up @@ -184,6 +189,17 @@ function checkParseFormat(path, paths) {
});
}

function checkSpecialCaseParseFormat(path, testCases) {
testCases.forEach(function(testCase) {
const element = testCase[0];
const expect = testCase[1];
const output = path.parse(element);
Object.keys(expect).forEach(function(key) {
assert.strictEqual(output[key], expect[key]);
});
});
}

function checkFormat(path, testCases) {
testCases.forEach(function(testCase) {
assert.strictEqual(path.format(testCase[0]), testCase[1]);
Expand Down

0 comments on commit 4717ea9

Please sign in to comment.