stripPathShortcuts removes any leading or trailing "../" from a given path
(p string)
| 181 | |
| 182 | // stripPathShortcuts removes any leading or trailing "../" from a given path |
| 183 | func stripPathShortcuts(p string) string { |
| 184 | newPath := path.Clean(p) |
| 185 | trimmed := strings.TrimPrefix(newPath, "../") |
| 186 | |
| 187 | for trimmed != newPath { |
| 188 | newPath = trimmed |
| 189 | trimmed = strings.TrimPrefix(newPath, "../") |
| 190 | } |
| 191 | |
| 192 | // trim leftover {".", ".."} |
| 193 | if newPath == "." || newPath == ".." { |
| 194 | newPath = "" |
| 195 | } |
| 196 | |
| 197 | if len(newPath) > 0 && string(newPath[0]) == "/" { |
| 198 | return newPath[1:] |
| 199 | } |
| 200 | |
| 201 | return newPath |
| 202 | } |
no outgoing calls
no test coverage detected