(path string)
| 512 | } |
| 513 | |
| 514 | func simpleNormalizePath(path string) (string, bool) { |
| 515 | // Most paths don't require normalization |
| 516 | if !hasRelativePathSegment(path) { |
| 517 | return path, true |
| 518 | } |
| 519 | // Some paths only require cleanup of `/./` or leading `./` |
| 520 | simplified := strings.ReplaceAll(path, "/./", "/") |
| 521 | trimmed := strings.TrimPrefix(simplified, "./") |
| 522 | if trimmed != path && !hasRelativePathSegment(trimmed) && !(trimmed != simplified && strings.HasPrefix(trimmed, "/")) { |
| 523 | // If we trimmed a leading "./" and the path now starts with "/", we changed the meaning |
| 524 | path = trimmed |
| 525 | return path, true |
| 526 | } |
| 527 | return "", false |
| 528 | } |
| 529 | |
| 530 | // hasRelativePathSegment reports whether p contains ".", "..", "./", "../", "/.", "/..", "//", "/./", or "/../". |
| 531 | func hasRelativePathSegment(p string) bool { |
no test coverage detected