diff options
author | Steven Lehn <sjlehn@gmail.com> | 2017-04-27 19:22:03 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-05-08 00:54:54 +0300 |
commit | cbd6fde9a38687491452e01927da0c69d2c37564 (patch) | |
tree | 02260b0145503a87d31cfe4419659a7258aef626 /doc/api/path.md | |
parent | 152966dbb5fc184a7cf12ce9e0ac0c0cbe8714d4 (diff) |
doc: improve path.posix.normalize docs
Add section to path docs that explains that path.posix.normalize
does not replace Windows slashes with POSIX slashes because POSIX
does not recognize / as a valid path separator.
Fixes: https://github.com/nodejs/node/issues/12298
PR-URL: https://github.com/nodejs/node/pull/12700
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Cai <davidcai1993@yahoo.com>
Diffstat (limited to 'doc/api/path.md')
-rw-r--r-- | doc/api/path.md | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/doc/api/path.md b/doc/api/path.md index d9452b00dbf..0b6e41c29a2 100644 --- a/doc/api/path.md +++ b/doc/api/path.md @@ -318,8 +318,9 @@ The `path.normalize()` method normalizes the given `path`, resolving `'..'` and `'.'` segments. When multiple, sequential path segment separation characters are found (e.g. -`/` on POSIX and `\` on Windows), they are replaced by a single instance of the -platform specific path segment separator. Trailing separators are preserved. +`/` on POSIX and either `\` or `/` on Windows), they are replaced by a single +instance of the platform specific path segment separator (`/` on POSIX and +`\` on Windows). Trailing separators are preserved. If the `path` is a zero-length string, `'.'` is returned, representing the current working directory. @@ -338,6 +339,14 @@ path.normalize('C:\\temp\\\\foo\\bar\\..\\'); // Returns: 'C:\\temp\\foo\\' ``` +Since Windows recognizes multiple path separators, both separators will be +replaced by instances of the Windows preferred separator (`\`): + +```js +path.win32.normalize('C:////temp\\\\/\\/\\/foo/bar'); +// Returns: 'C:\\temp\\foo\\bar' +``` + A [`TypeError`][] is thrown if `path` is not a string. ## path.parse(path) |