Skip to content

Commit

Permalink
path: fix win32.isAbsolute() inconsistency
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mscdex authored and Myles Borins committed Apr 5, 2016
1 parent aa9fb03 commit 1c40079
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 50 deletions.
60 changes: 10 additions & 50 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,57 +439,17 @@ const win32 = {
if (len === 0)
return false;
var code = path.charCodeAt(0);
if (len > 1) {
if (code === 47/*/*/ || code === 92/*\*/) {
// Possible UNC root

code = path.charCodeAt(1);
if (code === 47/*/*/ || code === 92/*\*/) {
// Matched double path separator at beginning
var j = 2;
var last = j;
// Match 1 or more non-path separators
for (; j < len; ++j) {
code = path.charCodeAt(j);
if (code === 47/*/*/ || code === 92/*\*/)
break;
}
if (j < len && j !== last) {
// Matched!
last = j;
// Match 1 or more path separators
for (; j < len; ++j) {
code = path.charCodeAt(j);
if (code !== 47/*/*/ && code !== 92/*\*/)
break;
}
if (j < len && j !== last) {
// Matched!
last = j;
// Match 1 or more non-path separators
for (; j < len; ++j) {
code = path.charCodeAt(j);
if (code === 47/*/*/ || code === 92/*\*/)
break;
}
if (j !== last)
return true;
}
}
}
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
(code >= 97/*a*/ && code <= 122/*z*/)) {
// Possible device root

code = path.charCodeAt(1);
if (path.charCodeAt(1) === 58/*:*/ && len > 2) {
code = path.charCodeAt(2);
if (code === 47/*/*/ || code === 92/*\*/)
return true;
}
}
} else if (code === 47/*/*/ || code === 92/*\*/) {
if (code === 47/*/*/ || code === 92/*\*/) {
return true;
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
(code >= 97/*a*/ && code <= 122/*z*/)) {
// Possible device root

if (len > 2 && path.charCodeAt(1) === 58/*:*/) {
code = path.charCodeAt(2);
if (code === 47/*/*/ || code === 92/*\*/)
return true;
}
}
return false;
},
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,18 @@ assert.equal(failures.length, 0, failures.join(''));


// path.isAbsolute tests
assert.equal(path.win32.isAbsolute('/'), true);
assert.equal(path.win32.isAbsolute('//'), true);
assert.equal(path.win32.isAbsolute('//server'), true);
assert.equal(path.win32.isAbsolute('//server/file'), true);
assert.equal(path.win32.isAbsolute('\\\\server\\file'), true);
assert.equal(path.win32.isAbsolute('\\\\server'), true);
assert.equal(path.win32.isAbsolute('\\\\'), true);
assert.equal(path.win32.isAbsolute('c'), false);
assert.equal(path.win32.isAbsolute('c:'), false);
assert.equal(path.win32.isAbsolute('c:\\'), true);
assert.equal(path.win32.isAbsolute('c:/'), true);
assert.equal(path.win32.isAbsolute('c://'), true);
assert.equal(path.win32.isAbsolute('C:/Users/'), true);
assert.equal(path.win32.isAbsolute('C:\\Users\\'), true);
assert.equal(path.win32.isAbsolute('C:cwd/another'), false);
Expand Down

0 comments on commit 1c40079

Please sign in to comment.