Uh oh!
There was an error while loading. Please reload this page.
docs: explain why path.posix.normalize does not replace windows slashes - #12700
docs: explain why path.posix.normalize does not replace windows slashes#12700sjlehn wants to merge 6 commits into
Conversation
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
| of the `path` methods. | ||
| ### path.posix.normalize(path) | ||
| The `path.posix.normalize()` method will not attempt to convert / (Windows) to \ (POSIX), as / is not recognized by |
There was a problem hiding this comment.
long line here. Please line break at 80 chars :-)
Fix formatting (long line) Fixes: #12298
| The `path.posix` property provides access to POSIX specific implementations | ||
| of the `path` methods. | ||
| ### path.posix.normalize(path) |
There was a problem hiding this comment.
I think this note belongs in the normalize() documentation, not as a different subsection in path.posix.
There was a problem hiding this comment.
Should I still give it a heading or would it be better as just a note after "For Example, on POSIX" at 327
| ### path.posix.normalize(path) | ||
| The `path.posix.normalize()` method will not attempt to convert / (Windows) to | ||
| \ (POSIX), as / is not recognized by POSIX as a valid directory separator. |
There was a problem hiding this comment.
Isn't / a valid directory separator on POSIX??
There was a problem hiding this comment.
duh...should have realized I had that backwards
There was a problem hiding this comment.
I think the comment may have these backwards. The windows separator \ is not recognized by POSIX as a valid separator.
Move the comment up to the main path.normalize section and fix the mix-up with / and \ Fixes: #12298
jasnell
left a comment
There was a problem hiding this comment.
LGTM with a couple of suggestions
| For example: | ||
| ```js | ||
| path.posix.normalize("\\some\\thing\\like\\this") |
There was a problem hiding this comment.
Suggestion: include .. in the sample path to show that those segments are not removed from the normalized path.
| ``` | ||
| *Note*: The `path.posix.normalize()` method will not attempt to convert \ | ||
| (Windows) to / (POSIX), as \ is not recognized by POSIX as a valid directory | ||
| separator. |
There was a problem hiding this comment.
Suggestion: wrap the \ and / in backticks...
`\` and `/`
Couple more formatting changes as requested in review: add backticks to slashes, and add .. to example path. Fixes: #12298
| For example: | ||
| ```js | ||
| path.posix.normalize("\\..\\some\\thing\\like\\this") | ||
| //Returns '\..\some\thing\like\this' |
There was a problem hiding this comment.
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)
vsemozhetbyt
commented
Apr 27, 2017
Typo in the PR and first commit message: |
vsemozhetbyt
commented
Apr 27, 2017
Linter: |
| path.normalize('/foo/bar//baz/asdf/quux/..'); | ||
| // Returns: '/foo/bar/baz/asdf' | ||
| ``` | ||
| *Note*: The `path.posix.normalize()` method will not attempt to convert `\ ` |
There was a problem hiding this comment.
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.
Reword note to describe what the method does, rather than what it doesn't do, per PR feedback Fixes: #12298
| `/` 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
So you're saying I should clarify what "platform specific path segment operator" means in each case?
There was a problem hiding this comment.
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.
Clarify "platform specific separator" Fixes: #12298
sjlehn
commented
May 4, 2017
@sam-github updated. Anything else I should review, or is it good? |
Landed in 9caf78fbaa573bf65f6bbfb27643c072d724481a, fixed up linter errors and commit message while landing. Thanks for the PR! :) edit: oops, forgot to |
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 <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Cai <davidcai1993@yahoo.com>
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: nodejs#12298 PR-URL: nodejs#12700 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Cai <davidcai1993@yahoo.com>
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 <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Cai <davidcai1993@yahoo.com>
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 <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Cai <davidcai1993@yahoo.com>
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
Added a note about directory separator conversion under path.posix.
Checklist
Affected core subsystem(s)
doc