Skip to content

Commit 1c40079

Browse files
mscdexMyles Borins
authored andcommitted
path: fix win32.isAbsolute() inconsistency
This commit fixes an inconsistency in absolute path checking compared to the absolute path detection used by the other path.win32 functions. Fixes: #6027 PR-URL: #6028 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent aa9fb03 commit 1c40079

File tree

2 files changed

+20
-50
lines changed

2 files changed

+20
-50
lines changed

lib/path.js

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -439,57 +439,17 @@ const win32 = {
439439
if (len === 0)
440440
return false;
441441
var code = path.charCodeAt(0);
442-
if (len > 1) {
443-
if (code === 47/*/*/ || code === 92/*\*/) {
444-
// Possible UNC root
445-
446-
code = path.charCodeAt(1);
447-
if (code === 47/*/*/ || code === 92/*\*/) {
448-
// Matched double path separator at beginning
449-
var j = 2;
450-
var last = j;
451-
// Match 1 or more non-path separators
452-
for (; j < len; ++j) {
453-
code = path.charCodeAt(j);
454-
if (code === 47/*/*/ || code === 92/*\*/)
455-
break;
456-
}
457-
if (j < len && j !== last) {
458-
// Matched!
459-
last = j;
460-
// Match 1 or more path separators
461-
for (; j < len; ++j) {
462-
code = path.charCodeAt(j);
463-
if (code !== 47/*/*/ && code !== 92/*\*/)
464-
break;
465-
}
466-
if (j < len && j !== last) {
467-
// Matched!
468-
last = j;
469-
// Match 1 or more non-path separators
470-
for (; j < len; ++j) {
471-
code = path.charCodeAt(j);
472-
if (code === 47/*/*/ || code === 92/*\*/)
473-
break;
474-
}
475-
if (j !== last)
476-
return true;
477-
}
478-
}
479-
}
480-
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
481-
(code >= 97/*a*/ && code <= 122/*z*/)) {
482-
// Possible device root
483-
484-
code = path.charCodeAt(1);
485-
if (path.charCodeAt(1) === 58/*:*/ && len > 2) {
486-
code = path.charCodeAt(2);
487-
if (code === 47/*/*/ || code === 92/*\*/)
488-
return true;
489-
}
490-
}
491-
} else if (code === 47/*/*/ || code === 92/*\*/) {
442+
if (code === 47/*/*/ || code === 92/*\*/) {
492443
return true;
444+
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
445+
(code >= 97/*a*/ && code <= 122/*z*/)) {
446+
// Possible device root
447+
448+
if (len > 2 && path.charCodeAt(1) === 58/*:*/) {
449+
code = path.charCodeAt(2);
450+
if (code === 47/*/*/ || code === 92/*\*/)
451+
return true;
452+
}
493453
}
494454
return false;
495455
},

test/parallel/test-path.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,18 @@ assert.equal(failures.length, 0, failures.join(''));
443443

444444

445445
// path.isAbsolute tests
446+
assert.equal(path.win32.isAbsolute('/'), true);
447+
assert.equal(path.win32.isAbsolute('//'), true);
448+
assert.equal(path.win32.isAbsolute('//server'), true);
446449
assert.equal(path.win32.isAbsolute('//server/file'), true);
447450
assert.equal(path.win32.isAbsolute('\\\\server\\file'), true);
451+
assert.equal(path.win32.isAbsolute('\\\\server'), true);
452+
assert.equal(path.win32.isAbsolute('\\\\'), true);
453+
assert.equal(path.win32.isAbsolute('c'), false);
454+
assert.equal(path.win32.isAbsolute('c:'), false);
455+
assert.equal(path.win32.isAbsolute('c:\\'), true);
456+
assert.equal(path.win32.isAbsolute('c:/'), true);
457+
assert.equal(path.win32.isAbsolute('c://'), true);
448458
assert.equal(path.win32.isAbsolute('C:/Users/'), true);
449459
assert.equal(path.win32.isAbsolute('C:\\Users\\'), true);
450460
assert.equal(path.win32.isAbsolute('C:cwd/another'), false);

0 commit comments

Comments
 (0)