-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
path: fix win32.isAbsolute() #6028
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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*/) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason this check is required? It only seems to matter for invalid paths, something like And slightly from the Python one https://github.com/python/cpython/blob/1fe0fd9feb6a4472a9a1b186502eb9c0b2366326/Lib/ntpath.py#L67 Although at this point it's better to keep this way for BC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO being more strict is better anyway. I don't see Windows adopting anything other than ASCII alphabetic drive letters any time soon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, and it would be a breaking change anyway. OK, all questions addressed - LGTM. |
||
(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; | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is much simpler than the old code - any idea why it was so long and what purpose the checks served?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't recall offhand, probably just a misinterpretation of the old regexp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the new version is correct on its own - the old one is just weird.