Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: explain why path.posix.normalize does not replace windows slashes #12700

Closed
wants to merge 6 commits into from
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