-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
path: fix posix.relative returns different results #13738
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
Changes from 1 commit
466faeb
0864e8e
acfdb47
8d604e1
c8bbf22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
resolve only throw error when rely on cwd
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,6 +199,10 @@ const win32 = { | |
| path = arguments[i]; | ||
| } else if (!resolvedDevice) { | ||
| path = process.cwd(); | ||
|
|
||
| // If you use the current working directory, | ||
| // it is necessary to check whether the current platform support. | ||
| assertWindowsPlatform(process.platform); | ||
| } else { | ||
| // Windows has the concept of drive-specific current working | ||
| // directories. If we've resolved a drive letter but not yet an | ||
|
|
@@ -213,11 +217,14 @@ const win32 = { | |
| path.slice(0, 3).toLowerCase() !== | ||
| resolvedDevice.toLowerCase() + '\\') { | ||
| path = resolvedDevice + '\\'; | ||
| } else { | ||
| // If you use the current working directory, | ||
|
Member
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. // The the current working directory is used... |
||
| // it is necessary to check whether the current platform support. | ||
| assertWindowsPlatform(process.platform); | ||
| } | ||
| } | ||
|
|
||
| assertPath(path); | ||
| assertWindowsPlatform(process.platform); | ||
|
|
||
| // Skip empty entries | ||
| if (path.length === 0) { | ||
|
|
@@ -575,8 +582,38 @@ const win32 = { | |
| if (from === to) | ||
| return ''; | ||
|
|
||
| var fromOrig = win32.resolve(from); | ||
| var toOrig = win32.resolve(to); | ||
| var fromOrig; | ||
| var toOrig; | ||
| var isFromAbsolute = true; | ||
| var isToAbsolute = true; | ||
|
|
||
| try { | ||
| fromOrig = win32.resolve(from); | ||
| } catch (err) { | ||
| if (err.code === 'ERR_UNSUPPORTED_PLATFORM') | ||
| isFromAbsolute = false; | ||
| } | ||
| try { | ||
| toOrig = win32.resolve(to); | ||
| } catch (err) { | ||
| if (err.code === 'ERR_UNSUPPORTED_PLATFORM') | ||
| isToAbsolute = false; | ||
| } | ||
|
|
||
| if (process.platform !== 'win32') { | ||
| if (!isFromAbsolute && !isToAbsolute) { | ||
|
Contributor
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. looks like you can do this separately for if (isFromAbsolute) ...
else ...
if (isToAbsolute) ...
else ...Or maybe I'm wrong?
Contributor
Author
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. Because need to know both type of
Contributor
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. Ok 👍 |
||
| from = 'c:\\fakepath\\' + from; | ||
|
Contributor
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. store the surrogate in a
Contributor
Author
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. 👌 |
||
| to = 'c:\\fakepath\\' + to; | ||
| fromOrig = win32.resolve(from); | ||
| toOrig = win32.resolve(to); | ||
| } else if (isFromAbsolute && !isToAbsolute) { | ||
| to = from + '\\' + to; | ||
| toOrig = win32.resolve(to); | ||
| } else if (!isFromAbsolute && isToAbsolute) { | ||
| from = to + '\\' + from; | ||
| fromOrig = win32.resolve(from); | ||
| } | ||
| } | ||
|
|
||
| if (fromOrig === toOrig) | ||
| return ''; | ||
|
|
@@ -1177,7 +1214,6 @@ const posix = { | |
| } | ||
|
|
||
| assertPath(path); | ||
| assertPosixPlatform(process.platform); | ||
|
|
||
| // Skip empty entries | ||
| if (path.length === 0) { | ||
|
|
@@ -1188,6 +1224,11 @@ const posix = { | |
| resolvedAbsolute = path.charCodeAt(0) === 47/*/*/; | ||
| } | ||
|
|
||
| // If you use the current working directory, | ||
| // it is necessary to check whether the current platform support. | ||
| if (cwd) | ||
| assertPosixPlatform(process.platform); | ||
|
|
||
| // At this point the path should be resolved to a full absolute path, but | ||
| // handle relative paths to be safe (might happen when process.cwd() fails) | ||
|
|
||
|
|
@@ -1263,8 +1304,35 @@ const posix = { | |
| if (from === to) | ||
| return ''; | ||
|
|
||
| from = posix.resolve(from); | ||
| to = posix.resolve(to); | ||
| var isFromAbsolute = true; | ||
| var isToAbsolute = true; | ||
| try { | ||
| from = posix.resolve(from); | ||
| } catch (err) { | ||
| if (err.code === 'ERR_UNSUPPORTED_PLATFORM') | ||
| isFromAbsolute = false; | ||
| } | ||
| try { | ||
| to = posix.resolve(to); | ||
| } catch (err) { | ||
| if (err.code === 'ERR_UNSUPPORTED_PLATFORM') | ||
| isToAbsolute = false; | ||
| } | ||
|
|
||
| if (process.platform === 'win32') { | ||
| if (!isFromAbsolute && !isToAbsolute) { | ||
| from = '/fakepath/' + from; | ||
|
Contributor
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. wrap (same as above) |
||
| to = '/fakepath/' + to; | ||
| from = posix.resolve(from); | ||
| to = posix.resolve(to); | ||
| } else if (isFromAbsolute && !isToAbsolute) { | ||
| to = from + '/' + to; | ||
| to = posix.resolve(to); | ||
| } else if (!isFromAbsolute && isToAbsolute) { | ||
| from = to + '/' + from; | ||
| from = posix.resolve(from); | ||
| } | ||
| } | ||
|
|
||
| if (from === to) | ||
| return ''; | ||
|
|
||
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.
// If the current working directory is used ...