MCPcopy Create free account
hub / github.com/bufbuild/buf / NormalizeAndValidate

Function NormalizeAndValidate

private/pkg/normalpath/normalpath_unix.go:34–45  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
34func 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//

Calls 2

NormalizeFunction · 0.85
NewErrorFunction · 0.85

Tested by 2

TestNormalizeAndValidateFunction · 0.56
TestNormalizeAndValidateFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…