diff --git a/pkg/api/instance_handler.go b/pkg/api/instance_handler.go index df951ecca..7d59cd421 100644 --- a/pkg/api/instance_handler.go +++ b/pkg/api/instance_handler.go @@ -71,7 +71,7 @@ func UpdateInstance(instanceName string, instance models.Instance) error { return err } - log.Infof("Instance %s updated", instance.Name) + fmt.Printf("Instance %s updated\n", instance.Name) return nil } diff --git a/pkg/utils/helper.go b/pkg/utils/helper.go index 9255129c7..77c6f2286 100644 --- a/pkg/utils/helper.go +++ b/pkg/utils/helper.go @@ -177,10 +177,11 @@ func ValidateRegistryName(rn string) bool { return re.MatchString(rn) } -// ValidateURL checks if the URL has valid format, non-empty host, and host is a valid IP or domain. -// Domain regex: labels must start/end with alphanumeric, can contain hyphens, max 63 chars, TLD min 2 letters. +// ValidateURL checks that the URL has a valid format and a non-empty host. +// The host may be an IP address, "localhost", or an RFC 1123-style hostname validated by domainNameRegex. func ValidateURL(rawURL string) error { - var domainNameRegex = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$`) + pattern := `^(?i:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$` + domainNameRegex := regexp.MustCompile(pattern) parsedURL, err := url.ParseRequestURI(rawURL) if err != nil { diff --git a/pkg/utils/helper_test.go b/pkg/utils/helper_test.go index 33c3aba4d..4e4ff8c6c 100644 --- a/pkg/utils/helper_test.go +++ b/pkg/utils/helper_test.go @@ -147,6 +147,9 @@ func TestValidateURL(t *testing.T) { {"valid localhost https", "https://localhost", false}, {"valid localhost http with port", "http://localhost:8080", false}, {"valid localhost https with port", "https://localhost:8443", false}, + {"valid single-label hostname", "http://harbor", false}, + {"valid single-label with hyphen", "https://registry-server", false}, + {"valid single-label with port", "http://harbor:8080", false}, // invalid URLs {"empty string", "", true},