Skip to content

Commit cbd6fde

Browse files
sjlehnaddaleax
authored andcommitted
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: #12298 PR-URL: #12700 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: David Cai <[email protected]>
1 parent 152966d commit cbd6fde

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

doc/api/path.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,9 @@ The `path.normalize()` method normalizes the given `path`, resolving `'..'` and
318318
`'.'` segments.
319319

320320
When multiple, sequential path segment separation characters are found (e.g.
321-
`/` on POSIX and `\` on Windows), they are replaced by a single instance of the
322-
platform specific path segment separator. Trailing separators are preserved.
321+
`/` on POSIX and either `\` or `/` on Windows), they are replaced by a single
322+
instance of the platform specific path segment separator (`/` on POSIX and
323+
`\` on Windows). Trailing separators are preserved.
323324

324325
If the `path` is a zero-length string, `'.'` is returned, representing the
325326
current working directory.
@@ -338,6 +339,14 @@ path.normalize('C:\\temp\\\\foo\\bar\\..\\');
338339
// Returns: 'C:\\temp\\foo\\'
339340
```
340341

342+
Since Windows recognizes multiple path separators, both separators will be
343+
replaced by instances of the Windows preferred separator (`\`):
344+
345+
```js
346+
path.win32.normalize('C:////temp\\\\/\\/\\/foo/bar');
347+
// Returns: 'C:\\temp\\foo\\bar'
348+
```
349+
341350
A [`TypeError`][] is thrown if `path` is not a string.
342351

343352
## path.parse(path)

0 commit comments

Comments
 (0)