diff --git a/pkg/fixedpoint/dec.go b/pkg/fixedpoint/dec.go index b1902f47b..f0cab3bfe 100644 --- a/pkg/fixedpoint/dec.go +++ b/pkg/fixedpoint/dec.go @@ -491,6 +491,9 @@ func (v *Value) Scan(src interface{}) error { // NewFromString parses a numeric string and returns a Value representation. func NewFromString(s string) (Value, error) { length := len(s) + if length == 0 { + return Zero, nil + } isPercentage := s[length-1] == '%' if isPercentage { s = s[:length-1] @@ -538,6 +541,9 @@ func MustNewFromString(input string) Value { func NewFromBytes(s []byte) (Value, error) { length := len(s) + if length == 0 { + return Zero, nil + } isPercentage := s[length-1] == '%' if isPercentage { s = s[:length-1] diff --git a/pkg/fixedpoint/dec_test.go b/pkg/fixedpoint/dec_test.go index 1a45c397c..517ea3562 100644 --- a/pkg/fixedpoint/dec_test.go +++ b/pkg/fixedpoint/dec_test.go @@ -126,6 +126,8 @@ func TestFromString(t *testing.T) { assert.Equal(t, "0.00000011", f.String()) f = MustNewFromString(".0%") assert.Equal(t, Zero, f) + f = MustNewFromString("") + assert.Equal(t, Zero, f) } func TestJson(t *testing.T) {