From 85c852cea89d06957628aeb8f57c9c20f58ef218 Mon Sep 17 00:00:00 2001 From: Sapphire Becker Date: Mon, 21 Aug 2023 11:07:12 -0700 Subject: [PATCH] check bin metadata first, require -bin be binary (technically breaking change) --- js/modules/k6/grpc/client.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/js/modules/k6/grpc/client.go b/js/modules/k6/grpc/client.go index 6aeb5df6600..73ab72db808 100644 --- a/js/modules/k6/grpc/client.go +++ b/js/modules/k6/grpc/client.go @@ -459,19 +459,17 @@ func (c *Client) parseInvokeParams(paramsVal goja.Value) (*invokeParams, error) } for hk, kv := range rawHeaders { // TODO(rogchap): Should we manage a string slice? - strval, ok := kv.(string) - if !ok { - // The spec defines that Binary-valued keys end in -bin - // https://grpc.io/docs/what-is-grpc/core-concepts/#metadata - if strings.HasSuffix(hk, "-bin") { - binval, ok := kv.([]byte) - if !ok { - return result, fmt.Errorf("metadata %q value must be a string or binary", hk) - } - strval = string(binval) - } else { - return result, fmt.Errorf("metadata %q value must be a string", hk) + // The spec defines that Binary-valued keys end in -bin + // https://grpc.io/docs/what-is-grpc/core-concepts/#metadata + var strval string + if strings.HasSuffix(hk, "-bin") { + binval, ok := kv.([]byte) + if !ok { + return result, fmt.Errorf("metadata %q value must be binary", hk) } + strval = string(binval) + } else if strval, ok = kv.(string); !ok { + return result, fmt.Errorf("metadata %q value must be a string", hk) } result.Metadata[hk] = strval }