fix nativeToUnixPath (#18501)
This commit is contained in:
parent
25efb53862
commit
923a1c6ea7
2 changed files with 28 additions and 3 deletions
|
|
@ -45,10 +45,15 @@ iterator walkDirRecFilter*(dir: string, follow: proc(entry: PathEntry): bool = n
|
||||||
|
|
||||||
proc nativeToUnixPath*(path: string): string =
|
proc nativeToUnixPath*(path: string): string =
|
||||||
# pending https://github.com/nim-lang/Nim/pull/13265
|
# 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 == '\\':
|
when DirSep == '\\':
|
||||||
result = replace(path, '\\', '/')
|
result = replace(result, '\\', '/')
|
||||||
else: result = path
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import sugar
|
import sugar
|
||||||
|
|
|
||||||
20
tests/stdlib/tglobs.nim
Normal file
20
tests/stdlib/tglobs.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
import std/private/globs
|
||||||
|
|
||||||
|
template main =
|
||||||
|
when defined(windows):
|
||||||
|
doAssert nativeToUnixPath("C:") == "/C"
|
||||||
|
doAssert nativeToUnixPath(r"D:\") == "/D/"
|
||||||
|
doAssert nativeToUnixPath(r"E:\a") == "/E/a"
|
||||||
|
doAssert nativeToUnixPath(r"E:\a1\") == "/E/a1/"
|
||||||
|
doAssert nativeToUnixPath(r"E:\a1\bc") == "/E/a1/bc"
|
||||||
|
doAssert nativeToUnixPath(r"\a1\bc") == "/a1/bc"
|
||||||
|
doAssert nativeToUnixPath(r"a1\bc") == "a1/bc"
|
||||||
|
doAssert nativeToUnixPath("a1") == "a1"
|
||||||
|
doAssert nativeToUnixPath("") == ""
|
||||||
|
doAssert nativeToUnixPath(".") == "."
|
||||||
|
doAssert nativeToUnixPath("..") == ".."
|
||||||
|
doAssert nativeToUnixPath(r"..\") == "../"
|
||||||
|
doAssert nativeToUnixPath(r"..\..\.\") == "../.././"
|
||||||
|
|
||||||
|
static: main()
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue