summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/os.nim6
-rw-r--r--tests/stdlib/tos.nim1
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 46e4e7b69..2919b39f0 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -349,10 +349,12 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
   ## If `path` has no extension, `ext` is the empty string.
   ## If `path` has no directory component, `dir` is the empty string.
   ## If `path` has no filename component, `name` and `ext` are empty strings.
-  if path.len == 0 or path[^1] in {DirSep, AltSep}:
+  if path.len == 0:
+      result = ("", "", "")
+  elif path[^1] in {DirSep, AltSep}:
     if path.len == 1:
       # issue #8255
-      result = (path[0 .. ^1], "", "")
+      result = ($path[0], "", "")
     else:
       result = (path[0 ..< ^1], "", "")
   else:
diff --git a/tests/stdlib/tos.nim b/tests/stdlib/tos.nim
index e49ab2506..577baea87 100644
--- a/tests/stdlib/tos.nim
+++ b/tests/stdlib/tos.nim
@@ -240,6 +240,7 @@ block absolutePath:
     doAssert absolutePath("/a", "b/") == "/a"
 
 block splitFile:
+  doAssert splitFile("") == ("", "", "")
   doAssert splitFile("abc/") == ("abc", "", "")
   doAssert splitFile("/") == ("/", "", "")
   doAssert splitFile("./abc") == (".", "abc", "")