Skip to content

Commit

Permalink
fix #13211 relativePath("foo", ".") (#13213)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour authored and Araq committed Jan 21, 2020
1 parent bf96d6d commit b355ef2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,10 @@ proc relativePath*(path, base: string; sep = DirSep): string {.
assert relativePath("/Users///me/bar//z.nim", "//Users/", '/') == "me/bar/z.nim"
assert relativePath("/Users/me/bar/z.nim", "/Users/me", '/') == "bar/z.nim"
assert relativePath("", "/users/moo", '/') == ""
assert relativePath("foo", ".", '/') == "foo"

if path.len == 0: return ""
let base = if base == ".": "" else: base

when doslikeFileSystem:
if isAbsolute(path) and isAbsolute(base):
Expand Down
4 changes: 4 additions & 0 deletions tests/stdlib/tos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ block ospaths:
doAssert relativePath("/foo", "/fOO", '/') == (when FileSystemCaseSensitive: "../foo" else: "")
doAssert relativePath("/foO", "/foo", '/') == (when FileSystemCaseSensitive: "../foO" else: "")

doAssert relativePath("foo", ".", '/') == "foo"
doAssert relativePath(".", ".", '/') == "."
doAssert relativePath("..", ".", '/') == ".."

when doslikeFileSystem:
doAssert relativePath(r"c:\foo.nim", r"C:\") == r"foo.nim"
doAssert relativePath(r"c:\foo\bar\baz.nim", r"c:\foo") == r"bar\baz.nim"
Expand Down

0 comments on commit b355ef2

Please sign in to comment.