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

path: make format() consistent and more functional #2408

Closed
wants to merge 1 commit into from

Conversation

nwoltman
Copy link
Contributor

This PR makes the win32 and posix versions of path.format() consistent in when they add a directory separator between the dir and base parts of the path (always add it unless the dir part is the same as the root part). This fixes the following inconsistencies:

path. Before After
win32.format({dir: 'folder\\', base: 'file.txt'}) 'folder\\file.txt' 'folder\\\\file.txt'
posix.format({dir: 'folder/', base: 'file.txt'}) 'folder//file.txt' (no change)
win32.format({root: 'C:\\', dir: 'C:\\'}) 'C:\\' (no change)
win32.format({root: '\\\\unc\\path\\', dir: '\\\\unc\\path\\'}) '\\\\unc\\path\\' (no change)
posix.format({root: '/', dir: '/'}) '//' '/'

This fixes bugs in path.format() and path.parse() being mirrors of each other (now they truly are mirrors for both win32 and posix).

Also, path.format() is now more functional in that it uses the name and ext parts of the path if the base part is left out, and it uses the root part if the dir part is left out. I added an example to the docs to show the new functionality.

I also removed the check for pathObject.root to be a string, partially because before this commit, pathObject.root wasn't being used for anything in the path.format() function, and also because if that part gets checked then all of the parts should get checked.

Alternatively, the code could check that all of the path parts in the pathObject are strings, in which case it could just go back to using only the dir and base parts (essentially expecting the input to only come from path.parse()).

The discussion for this originated here.

@Trott Trott added the path Issues and PRs related to the path subsystem. label Aug 17, 2015
@silverwind silverwind added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 18, 2015
@silverwind
Copy link
Contributor

Sorry for the delay. Starting this off with a CI: https://ci.nodejs.org/job/node-test-pull-request/257/

@nwoltman
Copy link
Contributor Author

Tests look good.
This is a semver-major change so should anyone else weigh in on this?

@nwoltman
Copy link
Contributor Author

Bump

@jasnell
Copy link
Member

jasnell commented Nov 16, 2015

@nodejs/ctc ... any thoughts on this one?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Nov 16, 2015
@nwoltman
Copy link
Contributor Author

Resolved conflicts

@rvagg
Copy link
Member

rvagg commented Nov 17, 2015

this seems reasonable to me, would be good to get @nodejs/platform-windows involved

@joaocgreis
Copy link
Member

LGTM

CI (with rebase to master): https://ci.nodejs.org/job/node-test-pull-request/775/

@@ -5,11 +5,12 @@ var path = require('path');

var winPaths = [
Copy link
Member

Choose a reason for hiding this comment

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

Since we're in here making changes anyway, the require decls and these top level decls could be change to const now

@jasnell
Copy link
Member

jasnell commented Nov 19, 2015

One comment, otherwise LGTM

Make the win32 and posix versions of path.format() consistent in when
they add a directory separator between the dir and base parts of the
path (always add it unless the dir part is the same as the root).

Also, path.format() is now more functional in that it uses the name
and ext parts of the path if the base part is left out and it uses
the root part if the dir part is left out.
@nwoltman
Copy link
Contributor Author

Changed top level vars in test file to const 👍

joaocgreis pushed a commit to JaneaSystems/node that referenced this pull request Nov 27, 2015
Make the win32 and posix versions of path.format() consistent in when
they add a directory separator between the dir and base parts of the
path (always add it unless the dir part is the same as the root).

Also, path.format() is now more functional in that it uses the name
and ext parts of the path if the base part is left out and it uses
the root part if the dir part is left out.

Reviewed-By: João Reis <reis@janeasystems.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#2408
@joaocgreis
Copy link
Member

Landed in d1000b4 .

@woollybogger thank you for the code and for your patience!

@joaocgreis joaocgreis closed this Nov 27, 2015
@nwoltman nwoltman deleted the path-parse branch December 13, 2015 23:03
@jasnell jasnell mentioned this pull request Mar 17, 2016
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
Make the win32 and posix versions of path.format() consistent in when
they add a directory separator between the dir and base parts of the
path (always add it unless the dir part is the same as the root).

Also, path.format() is now more functional in that it uses the name
and ext parts of the path if the base part is left out and it uses
the root part if the dir part is left out.

Reviewed-By: João Reis <reis@janeasystems.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#2408
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
path Issues and PRs related to the path subsystem. semver-major PRs that contain breaking changes and should be released in the next major version. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants