fix #13455 ; joinPath(a,b) now honors trailing slashes in b (or a if b = "") #13467
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix joinPath("", "") is "/" ; should be "" #13455 (fixes remaining cases after fix 3 minor bugs in joinPath (see #13455) #13462 was merged)
fixed behavior for variadic
joinPath
which was previously buggy as it didn't follow the same logic as joinPath (see some cases from joinPath("", "") is "/" ; should be "" #13455 ); it now simply calls the same routine as in joinPath.behavior for joinPath is now more natural, and consistent with D, nodejs, matlab, and more consistent with how other languages honor trailing slash:
joinPath(a,b)
now honors trailing slashes inb
(ora
ifb == ""
)in the sense that it ends with a trailing slash if b ends with a trailing slash, or if b is empty and a ends in a trailing slash.
see detailed test cases in PR.
changed behaviors since #13462 :
it's 100% consistent with how nodejs does it:
it's 100% consistent with how matlab, octave does it:
it's also consistent with how D does it
(as far as honoring trailing slash)
(but D differs in some other aspect,
buildPath("foo", "/bar")
would return"/bar"
; that's a separate topic)python
it's now consistent with how python honors trailing slash on
tail
:os.path.join("foo","bar")
'foo/bar'
os.path.join("foo","bar/")
'foo/bar/'
but now differs from python in behavior when tail is empty:
os.path.join("foo","")
'foo/'
note
the only controversial aspect in this PR is the edge case of whether
joinPath("foo", "")
should be "foo" (as in nodejs, D, go, matlab, and this PR) or "foo/" (as in python).IMO the way I did it makes more sense, with the semantic of
""
being an invalid path (unlike"."
), it collapses out, so thatjoinPath(foo1, "", foo2, "", "", bar, "") reduces to
joinPath(foo1, foo2, bar)
for example; it's also more consistent withjoinPath("", "")
being""