2
0

pathutil.go 437 B

1234567891011121314151617
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package pathutil
  5. import (
  6. "path"
  7. "strings"
  8. )
  9. // Clean cleans up given path and returns a relative path that goes straight
  10. // down to prevent path traversal.
  11. func Clean(p string) string {
  12. p = strings.ReplaceAll(p, `\`, "/")
  13. return strings.Trim(path.Clean("/"+p), "/")
  14. }