Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions internal/registry/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import (
)

var (
validCharsPattern = "[a-z0-9\\-.]+"
validCharsRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPattern))
validCharsPattern = "[a-z0-9\\-.]+"
validCharsPatternWithPort = "[a-z0-9\\-.:]+"
validCharsRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPattern))
validCharsPortRegexp = regexp.MustCompile(fmt.Sprintf("^%s$", validCharsPatternWithPort))
)

// IndexPath resolves the path for a specific namespace and name of buildpack
func IndexPath(rootDir, ns, name string) (string, error) {
if err := validateField("namespace", ns); err != nil {
if err := validateField("namespace", ns, validCharsPortRegexp); err != nil {
return "", err
}

if err := validateField("name", name); err != nil {
if err := validateField("name", name, validCharsRegexp); err != nil {
return "", err
}

Expand All @@ -40,7 +42,7 @@ func IndexPath(rootDir, ns, name string) (string, error) {
return filepath.Join(rootDir, indexDir, fmt.Sprintf("%s_%s", ns, name)), nil
}

func validateField(field, value string) error {
func validateField(field, value string, re *regexp.Regexp) error {
length := len(value)
switch {
case length == 0:
Expand All @@ -49,7 +51,7 @@ func validateField(field, value string) error {
return errors.Errorf("%s too long (max 253 chars)", style.Symbol(field))
}

if !validCharsRegexp.MatchString(value) {
if !re.MatchString(value) {
return errors.Errorf("%s contains illegal characters (must match %s)", style.Symbol(field), style.Symbol(validCharsPattern))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/buildpack/locator_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func GetLocatorType(locator string, relativeBaseDir string, buildpacksFromBuilde

if paths.IsURI(locator) {
if HasDockerLocator(locator) {
if _, err := name.ParseReference(locator); err == nil {
if _, err := name.ParseReference(ParsePackageLocator(locator)); err == nil {
return PackageLocator, nil
}
}
Expand Down
Loading