util: Add a bunch of tests

This improves our test coverage significantly.
This commit is contained in:
Ahmad Abuziad
2025-04-22 03:18:49 -04:00
committed by James Shubin
parent ae68dd79cb
commit c5d7fdb0a3
2 changed files with 858 additions and 0 deletions

View File

@@ -296,6 +296,9 @@ loop:
// SafePathClean does path.Clean, but it preserves any trailing slash if it was
// present in the initial path.
func SafePathClean(s string) string {
if s == "/" {
return "/"
}
hasSlash := strings.HasSuffix(s, "/")
clean := path.Clean(s) // removes trailing slashes
if hasSlash { // add it back if it was taken off