Browse Source

path: fix win32 parse()

Fix path.win32.parse("/foo/bar") retuns `{root: '' ...}`(v5.7.0),
but not `{root: '/' ...}`(v5.6.0).

PR-URL: https://github.com/nodejs/node/pull/5484
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Roman Reiss <me@silverwind.io>
process-exit-stdio-flushing
Zheng Chaoping 9 years ago
committed by Roman Reiss
parent
commit
4717ea9186
  1. 2
      lib/path.js
  2. 16
      test/parallel/test-path-parse-format.js

2
lib/path.js

@ -1007,8 +1007,8 @@ const win32 = {
isAbsolute = true; isAbsolute = true;
code = path.charCodeAt(1); code = path.charCodeAt(1);
if (code === 47/*/*/ || code === 92/*\*/) {
rootEnd = 1; rootEnd = 1;
if (code === 47/*/*/ || code === 92/*\*/) {
// Matched double path separator at beginning // Matched double path separator at beginning
var j = 2; var j = 2;
var last = j; var last = j;

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

@ -20,6 +20,10 @@ const winPaths = [
'\\\\?\\UNC\\server\\share' '\\\\?\\UNC\\server\\share'
]; ];
const winSpecialCaseParseTests = [
['/foo/bar', {root: '/'}]
];
const winSpecialCaseFormatTests = [ const winSpecialCaseFormatTests = [
[{dir: 'some\\dir'}, 'some\\dir\\'], [{dir: 'some\\dir'}, 'some\\dir\\'],
[{base: 'index.html'}, 'index.html'], [{base: 'index.html'}, 'index.html'],
@ -86,6 +90,7 @@ const errors = [
checkParseFormat(path.win32, winPaths); checkParseFormat(path.win32, winPaths);
checkParseFormat(path.posix, unixPaths); checkParseFormat(path.posix, unixPaths);
checkSpecialCaseParseFormat(path.win32, winSpecialCaseParseTests);
checkErrors(path.win32); checkErrors(path.win32);
checkErrors(path.posix); checkErrors(path.posix);
checkFormat(path.win32, winSpecialCaseFormatTests); checkFormat(path.win32, winSpecialCaseFormatTests);
@ -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) { function checkFormat(path, testCases) {
testCases.forEach(function(testCase) { testCases.forEach(function(testCase) {
assert.strictEqual(path.format(testCase[0]), testCase[1]); assert.strictEqual(path.format(testCase[0]), testCase[1]);

Loading…
Cancel
Save