NormalizeAndValidate normalizes and validates the given path. This calls Normalize on the path. Returns Error if the path is not relative or jumps context. This can be used to validate that paths are valid to use with Buckets. The error message is safe to pass to users.
(path string)
| 32 | // This can be used to validate that paths are valid to use with Buckets. |
| 33 | // The error message is safe to pass to users. |
| 34 | func NormalizeAndValidate(path string) (string, error) { |
| 35 | normalizedPath := Normalize(path) |
| 36 | if filepath.IsAbs(normalizedPath) { |
| 37 | return "", NewError(path, errNotRelative) |
| 38 | } |
| 39 | // https://github.com/bufbuild/buf/issues/51 |
| 40 | if strings.HasPrefix(normalizedPath, normalizedRelPathJumpContextPrefix) || |
| 41 | normalizedPath == normalizedRelPathJumpContextPath { |
| 42 | return "", NewError(path, errOutsideContextDir) |
| 43 | } |
| 44 | return normalizedPath, nil |
| 45 | } |
| 46 | |
| 47 | // EqualsOrContainsPath returns true if the value is equal to or contains the path. |
| 48 | // |
searching dependent graphs…