WithinBase reports whether target is base itself or contained under base.
(base, target string)
| 20 | |
| 21 | // WithinBase reports whether target is base itself or contained under base. |
| 22 | func WithinBase(base, target string) bool { |
| 23 | rel, err := filepath.Rel(base, target) |
| 24 | if err != nil { |
| 25 | return false |
| 26 | } |
| 27 | return rel == "." || (rel != ".." && !strings.HasPrefix(rel, ".."+string(os.PathSeparator))) |
| 28 | } |
no outgoing calls