Skip to content
Closed
9 changes: 9 additions & 0 deletions doc/api/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ For example on POSIX:
path.normalize('/foo/bar//baz/asdf/quux/..');
// Returns: '/foo/bar/baz/asdf'
```
*Note*: The `path.posix.normalize()` method will not attempt to convert `\ `
Copy link
Contributor

@sam-github sam-github Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note is backwards.

The docs clearly state normalize does two things: resolving . and .. segments, and collapsing multiple path seperators. Adding a statement about what it does NOT do is just strange.

The real problem is that the docs are wrong. On Windows, both / and \ are valid directory seperators (the docs are wrong here), and all sequences of 1 or more valid path seperator are replaced with a single preferred path seperator.

For POSIX, there is only one path seperator, so the set of valid and preferred is identical.

Fow Windows, it needs a special note, there are two valid seperators, but one is preferred, so seperators may actually be changed during normalize:

> path.win32.normalize("hi////there\\\\/\\/\\\/you/there")
'hi\\there\\you\\there'

Besides being documented, it would also be useful to have a couple examples.

(Windows) to `/` (POSIX), as `\ ` is not recognized by POSIX as a valid
directory separator.

For example:
```js
path.posix.normalize("\\..\\some\\thing\\like\\this")
//Returns '\..\some\thing\like\this'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not return that string:

> path.posix.normalize("\\..\\some\\thing\\like\\this")
'\\..\\some\\thing\\like\\this'

Either remove the string quotes, or leave the string quotes and properly escape the backslashes (I suggest the latter)

```

On Windows:

Expand Down