Uh oh!
There was an error while loading. Please reload this page.
path: make format() consistent and more functional - #2408
Conversation
silverwind
commented
Sep 6, 2015
Sorry for the delay. Starting this off with a CI: https://ci.nodejs.org/job/node-test-pull-request/257/ |
nwoltman
commented
Sep 17, 2015
Tests look good. |
nwoltman
commented
Oct 25, 2015
Bump |
jasnell
commented
Nov 16, 2015
@nodejs/ctc ... any thoughts on this one? |
nwoltman
commented
Nov 17, 2015
Resolved conflicts |
rvagg
commented
Nov 17, 2015
this seems reasonable to me, would be good to get @nodejs/platform-windows involved |
joaocgreis
commented
Nov 19, 2015
LGTM CI (with rebase to master): https://ci.nodejs.org/job/node-test-pull-request/775/ |
There was a problem hiding this comment.
Since we're in here making changes anyway, the require decls and these top level decls could be change to const now
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
commented
Nov 20, 2015
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
joaocgreis
commented
Nov 27, 2015
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
win32andposixversions ofpath.format()consistent in when they add a directory separator between the dir and base parts of the path (always add it unless thedirpart is the same as therootpart). 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 bothwin32andposix).Also,
path.format()is now more functional in that it uses thenameandextparts of the path if thebasepart is left out, and it uses therootpart if thedirpart is left out. I added an example to the docs to show the new functionality.I also removed the check for
pathObject.rootto be a string, partially because before this commit,pathObject.rootwasn'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
pathObjectare strings, in which case it could just go back to using only thedirandbaseparts (essentially expecting the input to only come frompath.parse()).The discussion for this originated here.