2020-02-19 23:45:02 +08:00
|
|
|
// 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"
|
|
|
|
|
)
|
|
|
|
|
|
2022-06-07 20:34:46 +08:00
|
|
|
// Clean cleans up given path and returns a relative path that goes straight
|
|
|
|
|
// down to prevent path traversal.
|
2020-02-19 23:45:02 +08:00
|
|
|
func Clean(p string) string {
|
2022-06-07 20:34:46 +08:00
|
|
|
p = strings.ReplaceAll(p, `\`, "/")
|
2020-02-19 23:45:02 +08:00
|
|
|
return strings.Trim(path.Clean("/"+p), "/")
|
|
|
|
|
}
|