This commit is contained in:
Takuya Igei 2021-11-26 20:27:40 +01:00 committed by GitHub
commit 9ca1f27511
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -40,6 +40,7 @@ const CHAR_FORWARD_SLASH = 47; /* / */
const CHAR_BACKWARD_SLASH = 92; /* \ */
const CHAR_COLON = 58; /* : */
const CHAR_QUESTION_MARK = 63; /* ? */
const CHAR_TILDE = 126; /* ~ */
class ErrorInvalidArgType extends Error {
code: 'ERR_INVALID_ARG_TYPE';
@ -232,6 +233,18 @@ export const win32: IPath = {
let isAbsolute = false;
const code = path.charCodeAt(0);
// Convert the leading tilde to home path. If the tilde is used
// as part of a filename or directory name, it will not be converted.
if (code === CHAR_TILDE &&
len === 1 ||
isPathSeparator(path.charCodeAt(1))) {
const userProfile = process.env['USERPROFILE'];
path = `${userProfile}\\${path.slice(1)}`;
rootEnd = 2;
isAbsolute = true;
}
// Try to match a root
if (len === 1) {
if (isPathSeparator(code)) {