From ed121b695e64200ed4b899d6fb84f667f276a5ce Mon Sep 17 00:00:00 2001 From: Lucca <109136188+LuccaBitfly@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:59:33 +0100 Subject: [PATCH] fix validator set dashboard ids (#95) --- backend/pkg/api/handlers/common.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/pkg/api/handlers/common.go b/backend/pkg/api/handlers/common.go index a8bb9a37f..26713d67e 100644 --- a/backend/pkg/api/handlers/common.go +++ b/backend/pkg/api/handlers/common.go @@ -2,6 +2,7 @@ package handlers import ( "bytes" + "encoding/base64" "encoding/json" "errors" "fmt" @@ -16,8 +17,6 @@ import ( "github.com/invopop/jsonschema" "github.com/xeipuuv/gojsonschema" - b64 "encoding/base64" - dataaccess "github.com/gobitfly/beaconchain/pkg/api/data_access" "github.com/gobitfly/beaconchain/pkg/api/enums" types "github.com/gobitfly/beaconchain/pkg/api/types" @@ -39,7 +38,7 @@ var ( reNumber = regexp.MustCompile(`^[0-9]+$`) reValidatorDashboardPublicId = regexp.MustCompile(`^v-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`) //reAccountDashboardPublicId = regexp.MustCompile(`^a-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`) - reValidatorPubkey = regexp.MustCompile(`^[0-9a-fA-F]{96}$`) + reValidatorPubkey = regexp.MustCompile(`^0x[0-9a-fA-F]{96}$`) reCursor = regexp.MustCompile(`^[0-9a-fA-F]*$`) ) @@ -89,12 +88,14 @@ func checkName(handlerErr *error, name string, minLength int) string { func checkMultipleRegex(handlerErr *error, regexes []*regexp.Regexp, params []string, paramName string) []string { results := make([]string, len(params)) - for i, param := range params { +OUTER: + for _, param := range params { for _, regex := range regexes { - checkRegex(handlerErr, regex, param, paramName) + if regex.MatchString(param) { + continue OUTER + } } - // might want to change this later - results[i] = params[i] + joinErr(handlerErr, fmt.Sprintf("given value '%s' for parameter '%s' has incorrect format", param, paramName)) } return results } @@ -190,7 +191,7 @@ func checkDashboardId(handlerErr *error, id string, acceptValidatorSet bool) int return nil } // given id must be an encoded set of validators - decodedId, err := b64.StdEncoding.DecodeString(id) + decodedId, err := base64.RawURLEncoding.DecodeString(id) if err != nil { joinErr(handlerErr, "invalid format for parameter 'dashboard_id'") return nil