Skip to content

Commit

Permalink
Compile the email regex only once
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
  • Loading branch information
rdimitrov committed Jun 20, 2024
1 parent d727e2a commit 96e4a9e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/controlplane/handlers_authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,15 @@ func (s *Server) removeRole(
}, nil
}

var emailRegex *regexp.Regexp

// isEmail checks if the subject is an email address or not
func isEmail(subject string) bool {
// Define the regular expression for validating an email address
const emailRegexPattern = `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
emailRegex := regexp.MustCompile(emailRegexPattern)
if emailRegex == nil {
emailRegex = regexp.MustCompile(emailRegexPattern)
}
return emailRegex.MatchString(subject)
}

Expand Down

0 comments on commit 96e4a9e

Please sign in to comment.