Skip to content

Commit

Permalink
fix 3 minor bugs in joinPath (see nim-lang#13455)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-mr committed Feb 21, 2020
1 parent 4cbeddd commit 6c5531b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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 head.len != 0 and head[^1] notin {DirSep, AltSep} and tail.len == 0:
result.add DirSep
else:
addNormalizePath(tail, result, state, DirSep)
Expand Down
3 changes: 2 additions & 1 deletion lib/pure/pathnorm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ proc addNormalizePath*(x: string; result: var string; state: var int;
while hasNext(it, x):
let b = next(it, x)
if (state shr 1 == 0) and isSlash(x, b):
result.add dirSep
if result.len == 0 or result[^1] notin {DirSep, AltSep}:
result.add dirSep
state = state or 1
elif isDotDot(x, b):
if (state shr 1) >= 1:
Expand Down
3 changes: 3 additions & 0 deletions tests/stdlib/tos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ block ospaths:
doAssert joinPath("", "lib") == "lib"
doAssert joinPath("", "/lib") == unixToNativePath"/lib"
doAssert joinPath("usr/", "/lib") == unixToNativePath"usr/lib"
doAssert joinPath("", "") == unixToNativePath""
doAssert joinPath("/" / "") == unixToNativePath"/"
doAssert joinPath("/", "/a/b/c") == unixToNativePath"/a/b/c"

block getTempDir:
block TMPDIR:
Expand Down

0 comments on commit 6c5531b

Please sign in to comment.