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
13 changes: 11 additions & 2 deletions doc/api/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,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. Trailing separators
Copy link
Contributor

@sam-github sam-github Apr 28, 2017

Choose a reason for hiding this comment

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

segment separator, path.sep.

windows has 2, the text above would allow normalize to replace all backslashes with a forwardslash on windows :-)

I suggest the link above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you're saying I should clarify what "platform specific path segment operator" means in each case?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes. you just said windows has two seperators, then said sequences are replaced by a single instance, but since there are two, which one does it get replace with? its described further down, but best make clear here.

are preserved.

If the `path` is a zero-length string, `'.'` is returned, representing the
current working directory.
Expand All @@ -338,6 +339,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)
Expand Down