MCPcopy Create free account
hub / github.com/github/gh-aw / validatePipPackageName

Function validatePipPackageName

pkg/workflow/name_validation.go:51–58  ·  view source on GitHub ↗

validatePipPackageName returns an error if the package name does not conform to the PyPI naming rules (PEP 508). This prevents argument injection into pip/uv.

(pkgName string)

Source from the content-addressed store, hash-verified

49// validatePipPackageName returns an error if the package name does not conform
50// to the PyPI naming rules (PEP 508). This prevents argument injection into pip/uv.
51func validatePipPackageName(pkgName string) error {
52 nameValidationLog.Printf("Validating pip package name: %s", pkgName)
53 if !pypiPackageNameRE.MatchString(pkgName) {
54 nameValidationLog.Printf("Invalid pip package name: %s", pkgName)
55 return fmt.Errorf("invalid pip package name: %q — PyPI names must start and end with a letter or digit, with hyphens, underscores, or dots allowed inside (e.g. \"requests\" or \"my-package\")", pkgName)
56 }
57 return nil
58}
59
60// rejectHyphenPrefixPackages returns a ValidationError if any of the provided
61// names starts with '-'. The kind parameter (e.g. "npx", "pip", "uv") is used

Calls 2

PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1