From 28add410c2ce67c487393b0a4b37c8f9bb8c5c26 Mon Sep 17 00:00:00 2001 From: Steven Lehn Date: Thu, 27 Apr 2017 11:22:03 -0500 Subject: [PATCH] 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 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: David Cai --- doc/api/path.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/api/path.md b/doc/api/path.md index a44bacb4657c10..9d1d4ce9176a4f 100644 --- a/doc/api/path.md +++ b/doc/api/path.md @@ -306,8 +306,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. @@ -326,6 +327,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)