fix 3 minor bugs in joinPath (see #13455) (#13462) [backport]

This commit is contained in:
Andrey Makarov 2020-02-23 22:22:46 +03:00 • committed by GitHub
commit 3dad130034
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 2 deletions

View file

@ -141,6 +141,7 @@ proc joinPath*(head, tail: string): string {.
when defined(posix):
assert joinPath("usr", "lib") == "usr/lib"
assert joinPath("usr", "") == "usr/"
assert joinPath("", "") == ""
assert joinPath("", "lib") == "lib"
assert joinPath("", "/lib") == "/lib"
assert joinPath("usr/", "/lib") == "usr/lib"
@ -149,7 +150,7 @@ proc joinPath*(head, tail: string): string {.
result = newStringOfCap(head.len + tail.len)
var state = 0
addNormalizePath(head, result, state, DirSep)
if tail.len == 0:
if result.len != 0 and result[^1] notin {DirSep, AltSep} and tail.len == 0:
result.add DirSep
else:
addNormalizePath(tail, result, state, DirSep)