From 04a76fa3251aa968bf214dbae1b48f1a6eb0f21c Mon Sep 17 00:00:00 2001 From: Fernando Alfaro Campos Date: Mon, 4 Jul 2022 14:31:53 -0400 Subject: [PATCH] Truncate snapshot name to max characters length --- service/controller.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/service/controller.go b/service/controller.go index bbf754bc..4d3f286d 100644 --- a/service/controller.go +++ b/service/controller.go @@ -3,6 +3,7 @@ package service import ( "errors" "fmt" + "math" "net/http" "strconv" "strings" @@ -1704,7 +1705,8 @@ func (s *service) CreateSnapshot( if req.Name != "" && len(req.Name) > 31 { name := req.Name name = strings.Replace(name, "snapshot-", "sn-", 1) - name = name[0:31] + length := int(math.Min(float64(len(name)), 31)) + name = name[0:length] Log.Printf("Requested name %s longer than 31 character max, truncated to %s\n", req.Name, name) req.Name = name }