parent
357edd86b4
commit
62c113ebc7
4 changed files with 21 additions and 0 deletions
|
|
@ -102,6 +102,8 @@ when true:
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
doAssert AbsoluteDir"/Users/me///" / RelativeFile"z.nim" == AbsoluteFile"/Users/me/z.nim"
|
doAssert AbsoluteDir"/Users/me///" / RelativeFile"z.nim" == AbsoluteFile"/Users/me/z.nim"
|
||||||
|
doAssert AbsoluteDir"/Users/me" / RelativeFile"../z.nim" == AbsoluteFile"/Users/z.nim"
|
||||||
|
doAssert AbsoluteDir"/Users/me/" / RelativeFile"../z.nim" == AbsoluteFile"/Users/z.nim"
|
||||||
doAssert relativePath("/foo/bar.nim", "/foo/", '/') == "bar.nim"
|
doAssert relativePath("/foo/bar.nim", "/foo/", '/') == "bar.nim"
|
||||||
doAssert $RelativeDir"foo/bar" == "foo/bar"
|
doAssert $RelativeDir"foo/bar" == "foo/bar"
|
||||||
doAssert RelativeDir"foo/bar" == RelativeDir"foo/bar"
|
doAssert RelativeDir"foo/bar" == RelativeDir"foo/bar"
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ template endsWith(a: string, b: set[char]): bool =
|
||||||
|
|
||||||
proc joinPathImpl(result: var string, state: var int, tail: string) =
|
proc joinPathImpl(result: var string, state: var int, tail: string) =
|
||||||
let trailingSep = tail.endsWith({DirSep, AltSep}) or tail.len == 0 and result.endsWith({DirSep, AltSep})
|
let trailingSep = tail.endsWith({DirSep, AltSep}) or tail.len == 0 and result.endsWith({DirSep, AltSep})
|
||||||
|
normalizePathEnd(result, trailingSep=false)
|
||||||
addNormalizePath(tail, result, state, DirSep)
|
addNormalizePath(tail, result, state, DirSep)
|
||||||
normalizePathEnd(result, trailingSep=trailingSep)
|
normalizePathEnd(result, trailingSep=trailingSep)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,11 @@ proc addNormalizePath*(x: string; result: var string; state: var int;
|
||||||
if (state shr 1) >= 1:
|
if (state shr 1) >= 1:
|
||||||
var d = result.len
|
var d = result.len
|
||||||
# f/..
|
# f/..
|
||||||
|
# We could handle stripping trailing sep here: foo// => foo like this:
|
||||||
|
# while (d-1) > (state and 1) and result[d-1] in {DirSep, AltSep}: dec d
|
||||||
|
# but right now we instead handle it inside os.joinPath
|
||||||
|
|
||||||
|
# strip path component: foo/bar => foo
|
||||||
while (d-1) > (state and 1) and result[d-1] notin {DirSep, AltSep}:
|
while (d-1) > (state and 1) and result[d-1] notin {DirSep, AltSep}:
|
||||||
dec d
|
dec d
|
||||||
if d > 0:
|
if d > 0:
|
||||||
|
|
|
||||||
|
|
@ -389,6 +389,19 @@ block ospaths:
|
||||||
doAssert joinPath("foo", "./") == unixToNativePath"foo/"
|
doAssert joinPath("foo", "./") == unixToNativePath"foo/"
|
||||||
doAssert joinPath("foo", "", "bar/") == unixToNativePath"foo/bar/"
|
doAssert joinPath("foo", "", "bar/") == unixToNativePath"foo/bar/"
|
||||||
|
|
||||||
|
# issue #13579
|
||||||
|
doAssert joinPath("/foo", "../a") == unixToNativePath"/a"
|
||||||
|
doAssert joinPath("/foo/", "../a") == unixToNativePath"/a"
|
||||||
|
doAssert joinPath("/foo/.", "../a") == unixToNativePath"/a"
|
||||||
|
doAssert joinPath("/foo/.b", "../a") == unixToNativePath"/foo/a"
|
||||||
|
doAssert joinPath("/foo///", "..//a/") == unixToNativePath"/a/"
|
||||||
|
doAssert joinPath("foo/", "../a") == unixToNativePath"a"
|
||||||
|
|
||||||
|
when doslikeFileSystem:
|
||||||
|
doAssert joinPath("C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\", "..\\..\\VC\\vcvarsall.bat") == r"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
|
||||||
|
doAssert joinPath("C:\\foo", "..\\a") == r"C:\a"
|
||||||
|
doAssert joinPath("C:\\foo\\", "..\\a") == r"C:\a"
|
||||||
|
|
||||||
block getTempDir:
|
block getTempDir:
|
||||||
block TMPDIR:
|
block TMPDIR:
|
||||||
# TMPDIR env var is not used if either of these are defined.
|
# TMPDIR env var is not used if either of these are defined.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue