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

Function NormalizeAndValidate

private/pkg/normalpath/normalpath_windows.go:32–47  ·  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

30// This can be used to validate that paths are valid to use with Buckets.
31// The error message is safe to pass to users.
32func NormalizeAndValidate(path string) (string, error) {
33 normalizedPath := Normalize(path)
34 if filepath.IsAbs(normalizedPath) || (len(normalizedPath) > 0 && normalizedPath[0] == '/') {
35 // the stdlib implementation of `IsAbs` assumes that a volume name is required for a path to
36 // be absolute, however Windows treats a `/` (normalized) rooted path as absolute _within_ the current volume.
37 // In the context of validating that a path is _not_ relative, we need to reject a path that begins
38 // with `/`.
39 return "", NewError(path, errNotRelative)
40 }
41 // https://github.com/bufbuild/buf/issues/51
42 if strings.HasPrefix(normalizedPath, normalizedRelPathJumpContextPrefix) ||
43 normalizedPath == normalizedRelPathJumpContextPath {
44 return "", NewError(path, errOutsideContextDir)
45 }
46 return normalizedPath, nil
47}
48
49// EqualsOrContainsPath returns true if the value is equal to or contains the path.
50// path is compared at each directory level to value for equivalency under simple unicode

Callers 15

ValidateProtoPathFunction · 0.92
GetMethod · 0.92
StatMethod · 0.92
WalkMethod · 0.92
WalkMethod · 0.92
getFullPathMethod · 0.92
DeleteAllMethod · 0.92
getFullPathMethod · 0.92
GetMethod · 0.92
StatMethod · 0.92
WalkMethod · 0.92

Calls 2

NormalizeFunction · 0.85
NewErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…