mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-04 19:04:46 +00:00
(cherry picked from commit 3dad130034)
This commit is contained in:
committed by
narimiran
parent
b6924383df
commit
fbf28d1ce7
@@ -130,6 +130,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"
|
||||
@@ -138,7 +139,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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -338,6 +338,10 @@ 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"
|
||||
doAssert joinPath("foo/","") == unixToNativePath"foo/"
|
||||
|
||||
block getTempDir:
|
||||
block TMPDIR:
|
||||
|
||||
Reference in New Issue
Block a user