From 8f2a9f048acc15f9fdc8fdbd46ee599968562595 Mon Sep 17 00:00:00 2001 From: Artem Poltorzhitskiy Date: Sun, 26 Mar 2023 16:08:48 +0400 Subject: [PATCH] Fix: add empty string to valid bytes sequence (#970) --- internal/bcd/ast/validators.go | 2 +- internal/bcd/ast/validators_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/bcd/ast/validators.go b/internal/bcd/ast/validators.go index 04ceef0d6..27d73111f 100644 --- a/internal/bcd/ast/validators.go +++ b/internal/bcd/ast/validators.go @@ -124,7 +124,7 @@ func BytesValidator(value string) error { if len(value)%2 > 0 { return errors.Wrapf(ErrValidation, "invalid bytes in hex length '%s'", value) } - if !hexRegex.MatchString(value) { + if value != "" && !hexRegex.MatchString(value) { return errors.Wrapf(ErrValidation, "bytes '%s' should be hexademical without prefixes", value) } return nil diff --git a/internal/bcd/ast/validators_test.go b/internal/bcd/ast/validators_test.go index 40d4d19e9..51fbfe9fb 100644 --- a/internal/bcd/ast/validators_test.go +++ b/internal/bcd/ast/validators_test.go @@ -125,6 +125,10 @@ func TestBytesValidator(t *testing.T) { name: "test 3", value: "0x030ed412d33412ab4b71df0aaba07df7ddd2a44eb55c87bf81868ba09a358bc0e0", wantErr: true, + }, { + name: "test 4", + value: "", + wantErr: false, }, } for _, tt := range tests {