stripPathShortcuts removes any leading or trailing "../" from a given path
(p string)
| 140 | |
| 141 | // stripPathShortcuts removes any leading or trailing "../" from a given path |
| 142 | func stripPathShortcuts(p string) string { |
| 143 | newPath := p |
| 144 | trimmed := strings.TrimPrefix(newPath, "../") |
| 145 | |
| 146 | for trimmed != newPath { |
| 147 | newPath = trimmed |
| 148 | trimmed = strings.TrimPrefix(newPath, "../") |
| 149 | } |
| 150 | |
| 151 | // trim leftover {".", ".."} |
| 152 | if newPath == "." || newPath == ".." { |
| 153 | newPath = "" |
| 154 | } |
| 155 | |
| 156 | if len(newPath) > 0 && string(newPath[0]) == "/" { |
| 157 | return newPath[1:] |
| 158 | } |
| 159 | |
| 160 | return newPath |
| 161 | } |
no outgoing calls
no test coverage detected