diff options
author | Andrey Makarov <ph.makarov@gmail.com> | 2020-02-23 22:22:46 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-23 20:22:46 +0100 |
commit | 3dad130034e3212159dda5d61988ca2b18959b24 (patch) | |
tree | 61b51d8a2305a18ca0e0551fdb30b07e670fc5ee /lib | |
parent | 13d292786e5a43b23f9a48643744c121c244b6ed (diff) | |
download | Nim-3dad130034e3212159dda5d61988ca2b18959b24.tar.gz |
fix 3 minor bugs in joinPath (see #13455) (#13462) [backport]
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/os.nim | 3 | ||||
-rw-r--r-- | lib/pure/pathnorm.nim | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index aff91fccb..5bdc5e11d 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -141,6 +141,7 @@ proc joinPath*(head, tail: string): string {. when defined(posix): assert joinPath("usr", "lib") == "usr/lib" assert joinPath("usr", "") == "usr/" + assert joinPath("", "") == "" assert joinPath("", "lib") == "lib" assert joinPath("", "/lib") == "/lib" assert joinPath("usr/", "/lib") == "usr/lib" @@ -149,7 +150,7 @@ proc joinPath*(head, tail: string): string {. result = newStringOfCap(head.len + tail.len) var state = 0 addNormalizePath(head, result, state, DirSep) - if tail.len == 0: + if result.len != 0 and result[^1] notin {DirSep, AltSep} and tail.len == 0: result.add DirSep else: addNormalizePath(tail, result, state, DirSep) diff --git a/lib/pure/pathnorm.nim b/lib/pure/pathnorm.nim index 407ec156c..3659e85e6 100644 --- a/lib/pure/pathnorm.nim +++ b/lib/pure/pathnorm.nim @@ -69,7 +69,8 @@ proc addNormalizePath*(x: string; result: var string; state: var int; while hasNext(it, x): let b = next(it, x) if (state shr 1 == 0) and isSlash(x, b): - result.add dirSep + if result.len == 0 or result[^1] notin {DirSep, AltSep}: + result.add dirSep state = state or 1 elif isDotDot(x, b): if (state shr 1) >= 1: |