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)
| 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. |
| 51 | func 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 |