-
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.relative(dir, dir) returns empty string #4826
Comments
I see what you mean, but |
That's not actually correct. Every directory has $ cd /tmp
$ cd ../var/./opt/../../.
$ pwd
/ |
Shouldn't |
No, that would imply there's another sub-directory like
Right, I see returning |
This is documented at https://nodejs.org/dist/latest-v5.x/docs/api/path.html#path_path_relative_from_to. I'll go ahead and close. Thanks! |
path.relative
returns empty string when itsfrom
andto
arguments are identical.Since
''
is not a valid path, this can blow up:This function
ls
works most of the time (nonexistent files and permissions aside), but not ifdir
points to the working directory:I find the fact that
path.relative
returns a valid path, except in one corner case when the two arguments are identical, rather inconvenient.However, this is probably intentional since there is a test for this introduced in #2106. But I haven't found any reasoning for this, and the reasoning of #2106 itself is not (directly) applicable here: it's one thing to defensively treat empty strings as
'.'
, and the other to return an empty string instead of a valid path.Expected bahavior:
The text was updated successfully, but these errors were encountered: