mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
@@ -14,6 +14,14 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CleanPath ensure to clean the path
|
||||
func CleanPath(p string) string {
|
||||
if strings.HasPrefix(p, "/") {
|
||||
return path.Clean(p)
|
||||
}
|
||||
return path.Clean("/" + p)[1:]
|
||||
}
|
||||
|
||||
// EnsureAbsolutePath ensure that a path is absolute, making it
|
||||
// relative to absoluteBase if necessary
|
||||
func EnsureAbsolutePath(path, absoluteBase string) string {
|
||||
|
@@ -136,3 +136,15 @@ func TestMisc_IsReadmeFileName(t *testing.T) {
|
||||
assert.Equal(t, testCase.idx, idx)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCleanPath(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"../../test": "test",
|
||||
"/test": "/test",
|
||||
"/../test": "/test",
|
||||
}
|
||||
|
||||
for k, v := range cases {
|
||||
assert.Equal(t, v, CleanPath(k))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user