-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Conversation
Sorry for the delay. Starting this off with a CI: https://ci.nodejs.org/job/node-test-pull-request/257/ |
Tests look good. |
Bump |
@nodejs/ctc ... any thoughts on this one? |
Resolved conflicts |
this seems reasonable to me, would be good to get @nodejs/platform-windows involved |
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 = [ |
There was a problem hiding this comment.
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
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.
Changed top level |
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
Landed in d1000b4 . @woollybogger thank you for the code and for your patience! |
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
This PR makes the
win32
andposix
versions ofpath.format()
consistent in when they add a directory separator between the dir and base parts of the path (always add it unless thedir
part is the same as theroot
part). This fixes the following inconsistencies:path.
win32.format({dir: 'folder\\', base: 'file.txt'})
'folder\\file.txt'
'folder\\\\file.txt'
posix.format({dir: 'folder/', base: 'file.txt'})
'folder//file.txt'
win32.format({root: 'C:\\', dir: 'C:\\'})
'C:\\'
win32.format({root: '\\\\unc\\path\\', dir: '\\\\unc\\path\\'})
'\\\\unc\\path\\'
posix.format({root: '/', dir: '/'})
'//'
'/'
This fixes bugs in
path.format()
andpath.parse()
being mirrors of each other (now they truly are mirrors for bothwin32
andposix
).Also,
path.format()
is now more functional in that it uses thename
andext
parts of the path if thebase
part is left out, and it uses theroot
part if thedir
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 thepath.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 thedir
andbase
parts (essentially expecting the input to only come frompath.parse()
).The discussion for this originated here.