From e5419fe64f2b5997580cfa4e0a1d66d8370ef80e Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 20 Jan 2020 15:56:08 -0800 Subject: [PATCH] fix #13211 relativePath("foo", ".") --- lib/pure/os.nim | 2 ++ tests/stdlib/tos.nim | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index a6b6ccffe3f3..3b1421cb56ed 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -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): diff --git a/tests/stdlib/tos.nim b/tests/stdlib/tos.nim index 35ea34841959..48202157ad56 100644 --- a/tests/stdlib/tos.nim +++ b/tests/stdlib/tos.nim @@ -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"