MCPcopy
hub / github.com/github/github-mcp-server / validateBlamePath

Function validateBlamePath

pkg/github/repositories.go:2370–2386  ·  view source on GitHub ↗

validateBlamePath rejects empty, leading-slash, traversal-laden, or control-character paths before any network call is made.

(p string)

Source from the content-addressed store, hash-verified

2368// validateBlamePath rejects empty, leading-slash, traversal-laden, or
2369// control-character paths before any network call is made.
2370func validateBlamePath(p string) error {
2371 if strings.TrimSpace(p) == "" {
2372 return fmt.Errorf("path must not be empty")
2373 }
2374 if strings.HasPrefix(p, "/") {
2375 return fmt.Errorf("path must be relative to the repository root (no leading '/')")
2376 }
2377 if slices.Contains(strings.Split(p, "/"), "..") {
2378 return fmt.Errorf("path must not contain '..' segments")
2379 }
2380 for _, r := range p {
2381 if r < 0x20 || r == 0x7f {
2382 return fmt.Errorf("path must not contain control characters")
2383 }
2384 }
2385 return nil
2386}
2387
2388func GetFileBlame(t translations.TranslationHelperFunc) inventory.ServerTool {
2389 st := NewTool(

Callers 1

GetFileBlameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected