Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/pure/pathnorm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ proc addNormalizePath*(x: string; result: var string; state: var int; dirSep = D
result.add dirSep
result.add substr(x, b[0], b[1])
inc state, 2
if result == "" and x != "": result = "."

proc normalizePath*(path: string; dirSep = DirSep): string =
## Example:
Expand All @@ -96,7 +97,7 @@ proc normalizePath*(path: string; dirSep = DirSep): string =
##
## - Turns multiple slashes into single slashes.
## - Resolves '/foo/../bar' to '/bar'.
## - Removes './' from the path.
## - Removes './' from the path (but "foo/.." becomes ".")
result = newStringOfCap(path.len)
var state = 0
addNormalizePath(path, result, state, dirSep)
7 changes: 5 additions & 2 deletions tests/stdlib/tos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,17 @@ block walkDirRec:
removeDir("walkdir_test")

block normalizedPath:
doAssert normalizedPath("") == ""
block relative:
doAssert normalizedPath(".") == ""
doAssert normalizedPath(".") == "."
doAssert normalizedPath("foo/..") == "."
doAssert normalizedPath("foo//../bar/.") == "bar"
doAssert normalizedPath("..") == ".."
doAssert normalizedPath("../") == ".."
doAssert normalizedPath("../..") == unixToNativePath"../.."
doAssert normalizedPath("../a/..") == ".."
doAssert normalizedPath("../a/../") == ".."
doAssert normalizedPath("./") == ""
doAssert normalizedPath("./") == "."

block absolute:
doAssert normalizedPath("/") == unixToNativePath"/"
Expand Down