repo/editor: clean up tree path

Fixes a security issue reported by @zeripath.
This commit is contained in:
ᴜɴᴋɴᴡᴏɴ
2020-02-19 23:45:02 +08:00
parent 33c6341ccd
commit ce1ec81d6f
3 changed files with 69 additions and 2 deletions

View File

@@ -0,0 +1,15 @@
// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package pathutil
import (
"path"
"strings"
)
// Clean cleans up given path and returns a relative path that goes straight down.
func Clean(p string) string {
return strings.Trim(path.Clean("/"+p), "/")
}