[os] fix #10017 regression, fix #10025 regression (#10018)

* [os] fix #10017 regression
* [os] fix #10025 regression
This commit is contained in:
Timothee Cour 2018-12-18 03:43:25 -08:00 • committed by Andreas Rumpf
commit 25d3539da7
2 changed files with 7 additions and 3 deletions

View file

@ -86,6 +86,7 @@ proc addNormalizePath*(x: string; result: var string; state: var int; dirSep = D
result.add dirSep result.add dirSep
result.add substr(x, b[0], b[1]) result.add substr(x, b[0], b[1])
inc state, 2 inc state, 2
if result == "" and x != "": result = "."
proc normalizePath*(path: string; dirSep = DirSep): string = proc normalizePath*(path: string; dirSep = DirSep): string =
## Example: ## Example:
@ -96,7 +97,7 @@ proc normalizePath*(path: string; dirSep = DirSep): string =
## ##
## - Turns multiple slashes into single slashes. ## - Turns multiple slashes into single slashes.
## - Resolves '/foo/../bar' to '/bar'. ## - Resolves '/foo/../bar' to '/bar'.
## - Removes './' from the path. ## - Removes './' from the path (but "foo/.." becomes ".")
result = newStringOfCap(path.len) result = newStringOfCap(path.len)
var state = 0 var state = 0
addNormalizePath(path, result, state, dirSep) addNormalizePath(path, result, state, dirSep)

View file

@ -190,14 +190,17 @@ block walkDirRec:
removeDir("walkdir_test") removeDir("walkdir_test")
block normalizedPath: block normalizedPath:
doAssert normalizedPath("") == ""
block relative: block relative:
doAssert normalizedPath(".") == "" doAssert normalizedPath(".") == "."
doAssert normalizedPath("foo/..") == "."
doAssert normalizedPath("foo//../bar/.") == "bar"
doAssert normalizedPath("..") == ".." doAssert normalizedPath("..") == ".."
doAssert normalizedPath("../") == ".." doAssert normalizedPath("../") == ".."
doAssert normalizedPath("../..") == unixToNativePath"../.." doAssert normalizedPath("../..") == unixToNativePath"../.."
doAssert normalizedPath("../a/..") == ".." doAssert normalizedPath("../a/..") == ".."
doAssert normalizedPath("../a/../") == ".." doAssert normalizedPath("../a/../") == ".."
doAssert normalizedPath("./") == "" doAssert normalizedPath("./") == "."
block absolute: block absolute:
doAssert normalizedPath("/") == unixToNativePath"/" doAssert normalizedPath("/") == unixToNativePath"/"