@@ -49,6 +49,12 @@ import (
4949
5050const ENV_DELETE_SUCCESS_RESP = "Environment deleted successfully."
5151
52+ var (
53+ // Regex patterns for environment name validation
54+ envNameAlphanumericRegex = regexp .MustCompile (`^[a-z0-9-]+$` )
55+ envNameLengthRegex = regexp .MustCompile (`^.{1,16}$` )
56+ )
57+
5258type EnvironmentRestHandler interface {
5359 Create (w http.ResponseWriter , r * http.Request )
5460 Get (w http.ResponseWriter , r * http.Request )
@@ -107,13 +113,6 @@ func NewEnvironmentRestHandlerImpl(svc request.EnvironmentService, environmentRe
107113 }
108114}
109115
110- var (
111- // Regex patterns for environment name validation
112- envNameAlphanumericRegex = regexp .MustCompile (`^[a-z0-9-]+$` )
113- envNameNoStartEndHyphen = regexp .MustCompile (`^(?![-]).*[^-]$` )
114- envNameLengthRegex = regexp .MustCompile (`^.{1,16}$` )
115- )
116-
117116// validateEnvironmentName validates the environment name against multiple regex patterns
118117// Note: Required validation is already handled by struct validation tag
119118func (impl EnvironmentRestHandlerImpl ) validateEnvironmentName (envName string ) error {
@@ -123,7 +122,7 @@ func (impl EnvironmentRestHandlerImpl) validateEnvironmentName(envName string) e
123122 }
124123
125124 // Validation 2: Cannot start/end with '-'
126- if ! envNameNoStartEndHyphen . MatchString (envName ) {
125+ if strings . HasPrefix (envName , "-" ) || strings . HasSuffix ( envName , "-" ) {
127126 return errors .New ("Cannot start/end with '-'" )
128127 }
129128
0 commit comments