-
-
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
path.posix and path.win32 doc
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -431,9 +431,38 @@ added: v0.11.15 | |
| The `path.posix` property provides access to POSIX specific implementations | ||
| of the `path` methods. | ||
|
|
||
| The following functions do not support direct use on Windows. | ||
| * path.posix.resolve | ||
| * path.posix.relative | ||
| *Note*: Be careful when using the following functions directly on Windows. | ||
|
|
||
| ### path.posix.resolve([...path]) | ||
| If after processing all given `path` segments an absolute path has not yet | ||
| been generated, `path.posix.resolve` will throw [`UNSUPPORTED_PLATFORM`] error. | ||
|
|
||
|
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. Perhaps: Then include a short snippet about why... Same with the
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. suggestion: *Note*: Care should be taken when using `path.posix.resolve()` on Windows due to the fact that resolve will use `process.cwd()` verbatim, and so the output will be a concatenation of Windows and POSIX style paths. |
||
| ### path.posix.relative(from, to) | ||
| If `from` and `to` are both relative path, `path.posix.relative` will use the | ||
|
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. Please include the |
||
| path `/fakepath/` as the current working path to generate the result. | ||
|
|
||
| For example | ||
|
|
||
| ``` | ||
| path.posix.relative('a/b/c', '../../x'); | ||
|
|
||
| // 'from' will be '/fakepath/a/b/c' | ||
| // 'to' will be '/fakepath/../../x', then will be normalized to '/x' | ||
| // Returns: '../../../../x' | ||
| ``` | ||
|
|
||
| If one of `from` and `to` is relative path, `path.posix.relative` will use the | ||
| other absolute path as the current working path to generate the result. | ||
|
|
||
| For example | ||
|
|
||
| ``` | ||
| path.posix.relative('/a/b/c', '../../x'); | ||
|
|
||
| // 'from' will be '/a/b/c' | ||
| // 'to' will be '/a/b/c/../../x', then will be normalized to '/a/x' | ||
| // Returns: '../../x' | ||
| ``` | ||
|
|
||
| ## path.relative(from, to) | ||
| <!-- YAML | ||
|
|
@@ -555,9 +584,38 @@ added: v0.11.15 | |
| The `path.win32` property provides access to Windows-specific implementations | ||
| of the `path` methods. | ||
|
|
||
| The following functions do not support direct use on *nix. | ||
| * path.win32.resolve | ||
| * path.win32.relative | ||
| *Note*: Be careful when using the following functions directly on POSIX. | ||
|
|
||
| ### path.win32.resolve([...path]) | ||
| If after processing all given `path` segments an absolute path has not yet | ||
| been generated, `path.win32.resolve` will throw [`UNSUPPORTED_PLATFORM`] error. | ||
|
|
||
| ### path.win32.relative(from, to) | ||
| If `from` and `to` are both relative path, `path.win32.relative` will use the | ||
| path `c:\\fakepath\\` as the current working path to generate the result. | ||
|
|
||
| For example | ||
|
|
||
| ``` | ||
| path.win32.relative('a\\b\\c', '..\\..\\x'); | ||
|
|
||
| // 'from' will be 'c:\\fakepath\\a\\b\\c' | ||
| // 'to' will be 'c:\\fakepath\\..\\..\\x', then will be normalized to 'c:\\x' | ||
| // Returns: '..\\..\\..\\..\\x' | ||
| ``` | ||
|
|
||
| If one of `from` and `to` is relative path, `path.win32.relative` will use the | ||
| other absolute path as the current working path to generate the result. | ||
|
|
||
| For example | ||
|
|
||
| ``` | ||
| path.win32.relative('c:\\a\\b\\c', '..\\..\\x'); | ||
|
|
||
| // 'from' will be 'c:\\a\\b\\c' | ||
| // 'to' will be 'c:\\a\\b\\c\\..\\..\\x', then will be normalized to 'c:\\a\\x' | ||
| // Returns: '..\\..\\x' | ||
| ``` | ||
|
|
||
| [`TypeError`]: errors.html#errors_class_typeerror | ||
| [`path.parse()`]: #path_path_parse_path | ||
|
|
||
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 note should be moved into the bodies of each of the API sections. Sitting above it, it is far more likely that the Note will become disconnected...