Skip to content

Commit

Permalink
fix #8395, fix #8734: normalize os.tailDir and os.parentDir
Browse files Browse the repository at this point in the history
  • Loading branch information
narimiran committed May 20, 2019
1 parent dc6a4b1 commit bf7ac7d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,10 @@ proc parentDir*(path: string): string {.
assert parentDir("./foo") == "."
assert parentDir("/foo") == ""

let sepPos = parentDirPos(path)
result = normalizePathEnd(path)
let sepPos = parentDirPos(result)
if sepPos >= 0:
result = substr(path, 0, sepPos-1)
result = substr(result, 0, sepPos-1)
else:
result = ""

Expand All @@ -350,11 +351,10 @@ proc tailDir*(path: string): string {.
assert tailDir("/usr/local/bin") == "usr/local/bin"
assert tailDir("usr/local/bin") == "local/bin"

var q = 1
if len(path) >= 1 and path[len(path)-1] in {DirSep, AltSep}: q = 2
for i in 0..len(path)-q:
if path[i] in {DirSep, AltSep}:
return substr(path, i+1)
result = normalizePathEnd(path)
for i in 0 .. result.high:
if result[i] in {DirSep, AltSep}:
return substr(result, i+1)
result = ""

proc isRootDir*(path: string): bool {.
Expand Down

0 comments on commit bf7ac7d

Please sign in to comment.