-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
doc: Adding note about empty strings in path module #2106
Conversation
nit: I think Nit aside, LGTM. |
path.isAbsolute('.') // false | ||
|
||
*Note:* If the path is a zero length string then `false` will be returned. |
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.
I'm not sure whether this is really clarifying anything?
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.
@brendanashworth Since it is a special case, I thought it would be better to document that as well. We can remove it, if it doesn't make much sense to keep.
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.
Your call - imo I would throw on this, but that is out of the picture so I'll leave it up to you.
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.
@brendanashworth Well, in other cases empty string means the current directory, and this is an exception. So, I think it would be better to leave it in.
809d8de
to
63874da
Compare
@Trott I have read in few places in the Internet that empty string sometimes means a string with only space characters as well. So, I ll better go with |
I like where this is going! I feel like the wording of "the path" could be a little bit ambiguous for some of them, like |
@brendanashworth Oh yeah, will |
@thefourtheye that doesn't specify which path string ( |
@brendanashworth It is applicable to both |
@brendanashworth I updated the messages a little bit based on your suggestion. PTAL. cc @Trott |
path.isAbsolute('.') // false | ||
|
||
*Note:* If the path string passed as parameter is a zero-length string, | ||
unlike other path module functions, zero-length string will be used | ||
as-is and `false` will be returned. |
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.
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.
If they aren't there already, maybe add tests for the situations covered by these notes and see what happens on CI. Then you will know for sure whether the behavior is universal or platform-dependent. Include comments indicating that the tests are there to cover edge cases noted in the documentation.
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.
@Fishrock123 I don't have a Windows machine, but when I tried in REPL, I got false
for both the versions.
@Trott Thanks for the suggestion man :-) I included a simple test now. PTAL.
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.
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.
@Trott Thank you :-) Looks like the test is passing in all the environments.
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.
Just manually tested on Windows for good measure, and path.isAbsolute('')
returned false
. So that seems OK.
The path module's `join, normalize, isAbsolute, relative and resolve` functions return/use the current directory if they are passed zero length strings. > process.version 'v2.3.4-pre' > path.win32.join('') '.' > path.posix.join('') '.' > path.win32.normalize('') '.' > path.posix.normalize('') '.' > path.win32.isAbsolute('') false > path.posix.isAbsolute('') false > path.win32.relative('', '') '' > path.posix.relative('', '') '' > path.win32relative('.', '') '' > path.posix.relative('.', '') '' > path.posix.resolve('') '/home/thefourtheye/Desktop' > path.win32.resolve('') '\\home\\thefourtheye\\Desktop' Since empty paths are not valid in any of the operating systems people normally use, this behaviour might be a surprise to the users. This commit introduces "Notes" about this, wherever applicable in `path`'s documentation.
These testcases are specific to one uncommon behaviour in path module. Few of the functions in path module, treat '' strings as current working directory. This test makes sure that the behaviour is intact between commits. See: nodejs#2106
10b2405
to
a65d5fd
Compare
Bump! |
LGTM. |
Unless someone beats me to it or raises an objection between now and then, I'll merge this some time in the next 48 to 72 hours (roughly some time on Tuesday PDT). |
Thanks @Trott :-) |
Rebased against master and running CI one more time for good measure: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/150/ |
The path module's `join, normalize, isAbsolute, relative and resolve` functions return/use the current directory if they are passed zero length strings. > process.version 'v2.3.4-pre' > path.win32.join('') '.' > path.posix.join('') '.' > path.win32.normalize('') '.' > path.posix.normalize('') '.' > path.win32.isAbsolute('') false > path.posix.isAbsolute('') false > path.win32.relative('', '') '' > path.posix.relative('', '') '' > path.win32relative('.', '') '' > path.posix.relative('.', '') '' > path.posix.resolve('') '/home/thefourtheye/Desktop' > path.win32.resolve('') '\\home\\thefourtheye\\Desktop' Since empty paths are not valid in any of the operating systems people normally use, this behaviour might be a surprise to the users. This commit introduces "Notes" about this, wherever applicable in `path`'s documentation. The tests makes sure that the behaviour is intact between commits. PR-URL: nodejs#2106 Reviewed-By: Rich Trott <[email protected]>
merged in 65963ec |
@Trott Thanks :-) |
The path module's
join, normalize, isAbsolute, relative and resolve
functions return/use the current directory if they are passed zero
length strings.
Since empty paths are not valid in any of the operating systems people
normally use, this behaviour might be a surprise to the users. This
commit introduces "Notes" about this, wherever applicable in
path
'sdocumentation.