filepath/clean: Add Windows support#539
Merged
Mashimiao merged 5 commits intoopencontainers:masterfrom Dec 13, 2017
Merged
Conversation
This catches us up with how the Linux stdlib implementation handles
this case:
$ cat test.go
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Println(filepath.Clean("a/.."))
}
$ go run test
.
by implementing the rule mentioned in [1].
[1]: https://golang.org/pkg/path/filepath/#Clean
Signed-off-by: W. Trevor King <wking@tremily.us>
And add tests to protect us from that in the future. Also throw in a /.. test with a non-.. tail for good measure. Signed-off-by: W. Trevor King <wking@tremily.us>
For the test cases that match the current GOOS. This ensures we stay consistent (at least for platforms where we run tests). Also drop an unecessary trailing newline from the old error message. Signed-off-by: W. Trevor King <wking@tremily.us>
For the test cases that match the current GOOS. This ensures we stay consistent (at least for platforms where we run tests). Also drop an unecessary trailing newline from the old error message. I don't compare for Abs, because the stdlib doesn't have a configurable cwd. We could check the current working directory [1,2,...], but I don't want to use the frozen syscall package and am not interested enough to import lots of per-OS x/sys packages. Also, the odds of the test working directory matching one of the cwd values (or even of those cwd values actually existing on the host) are small, and it would be even more work to temporarily change to (and possibly create) those directories per test. [1]: https://golang.org/pkg/syscall/#Getcwd [2]: https://godoc.org/golang.org/x/sys/unix#Getcwd Signed-off-by: W. Trevor King <wking@tremily.us>
3252cbd to
2f21180
Compare
And once we have Windows support for Clean, we can remove the guard from Abs. I don't have a Windows machine around to test with, so the expected values are my best guesses. Signed-off-by: W. Trevor King <wking@tremily.us>
Member
1 similar comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Also fix the Linux
Cleanhandling fora/..and/..and add logic to compare theGOOSCleanandIsAbsresults with the stdlib.This is an alternative to #536.