Skip to content

Commit 28add41

Browse files
sjlehnMylesBorins
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 8414659 commit 28add41

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
@@ -306,8 +306,9 @@ The `path.normalize()` method normalizes the given `path`, resolving `'..'` and
306306
`'.'` segments.
307307

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

312313
If the `path` is a zero-length string, `'.'` is returned, representing the
313314
current working directory.
@@ -326,6 +327,14 @@ path.normalize('C:\\temp\\\\foo\\bar\\..\\');
326327
// Returns: 'C:\\temp\\foo\\'
327328
```
328329

330+
Since Windows recognizes multiple path separators, both separators will be
331+
replaced by instances of the Windows preferred separator (`\`):
332+
333+
```js
334+
path.win32.normalize('C:////temp\\\\/\\/\\/foo/bar');
335+
// Returns: 'C:\\temp\\foo\\bar'
336+
```
337+
329338
A [`TypeError`][] is thrown if `path` is not a string.
330339

331340
## path.parse(path)

0 commit comments

Comments
 (0)