summary refs log tree commit diff stats
path: root/lib/std/private
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-07-16 22:54:47 -0700
committerGitHub <noreply@github.com>2021-07-17 07:54:47 +0200
commit923a1c6ea7d9f45b6389680717692690218228fb (patch)
tree0153da816e90e3b09b4937fe4233ecdbc2cbf13b /lib/std/private
parent25efb5386293540b0542833625d3fb6e22f3cfbc (diff)
downloadNim-923a1c6ea7d9f45b6389680717692690218228fb.tar.gz
fix nativeToUnixPath (#18501)
Diffstat (limited to 'lib/std/private')
-rw-r--r--lib/std/private/globs.nim11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/std/private/globs.nim b/lib/std/private/globs.nim
index 55f6a40bd..b3726c9c3 100644
--- a/lib/std/private/globs.nim
+++ b/lib/std/private/globs.nim
@@ -45,10 +45,15 @@ iterator walkDirRecFilter*(dir: string, follow: proc(entry: PathEntry): bool = n
 
 proc nativeToUnixPath*(path: string): string =
   # pending https://github.com/nim-lang/Nim/pull/13265
-  doAssert not path.isAbsolute # not implemented here; absolute files need more care for the drive
+  result = path
+  when defined(windows):
+    if path.len >= 2 and path[0] in {'a'..'z', 'A'..'Z'} and path[1] == ':':
+      result[0] = '/'
+      result[1] = path[0]
+      if path.len > 2 and path[2] != '\\':
+        doAssert false, "paths like `C:foo` are currently unsupported, path: " & path
   when DirSep == '\\':
-    result = replace(path, '\\', '/')
-  else: result = path
+    result = replace(result, '\\', '/')
 
 when isMainModule:
   import sugar