fix(math): FormatInt returns error on empty string (#15714)
This commit is contained in:
parent
17debf2efa
commit
43cfdfe618
@ -34,6 +34,12 @@ Ref: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.j
|
||||
|
||||
# Changelog
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* [#15714](https://github.com/cosmos/cosmos-sdk/pull/15714) `FormatInt` returns an error on empty string
|
||||
|
||||
## [math/v1.0.0](https://github.com/cosmos/cosmos-sdk/releases/tag/math/v1.0.0) - 2023-03-23
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@ -457,6 +457,10 @@ var stringsBuilderPool = &sync.Pool{
|
||||
// string following ADR-050. This function operates with string manipulation
|
||||
// (instead of manipulating the int or sdk.Int object).
|
||||
func FormatInt(v string) (string, error) {
|
||||
if len(v) == 0 {
|
||||
return "", fmt.Errorf("cannot format empty string")
|
||||
}
|
||||
|
||||
sign := ""
|
||||
if v[0] == '-' {
|
||||
sign = "-"
|
||||
|
||||
@ -473,6 +473,11 @@ func TestFormatIntNonDigits(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatIntEmptyString(t *testing.T) {
|
||||
_, err := math.FormatInt("")
|
||||
require.ErrorContains(t, err, "cannot format empty string")
|
||||
}
|
||||
|
||||
func TestFormatIntCorrectness(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
|
||||
Loading…
Reference in New Issue
Block a user