fix(textual): error if a formatted coin contains a comma (#19265)

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Facundo Medica 2024-01-29 18:22:38 +01:00 committed by GitHub
parent bb239a4571
commit 7d66bb3a50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -31,6 +31,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
### Bug Fixes
* [#19265](https://github.com/cosmos/cosmos-sdk/pull/19265) Reject denoms that contain a comma.
### Improvements
* [#18857](https://github.com/cosmos/cosmos-sdk/pull/18857) Moved `FormatCoins` from `core/coins` to this package under `signing/textual`.

View File

@ -284,6 +284,12 @@ func FormatCoins(coins []*basev1beta1.Coin, metadata []*bankv1beta1.Metadata) (s
if err != nil {
return "", err
}
// If a coin contains a comma, return an error given that the output
// could be misinterpreted by the user as 2 different coins.
if strings.Contains(formatted[i], ",") {
return "", fmt.Errorf("coin %s contains a comma", formatted[i])
}
}
if len(coins) == 0 {

View File

@ -327,5 +327,10 @@
{"text":"", "error": true},
{"text":"1COSM", "error": true},
{"text":"1 COSM", "error": true},
{"text":" 1 COSM", "error": true}
{"text":" 1 COSM", "error": true},
{
"proto": {"amount": "10000000", "denom": "point, 222222 point"},
"metadata": {"display": "POINT", "base": "point", "denom_units": [{"denom": "point", "exponent": 0}, {"denom": "POINT", "exponent": 0}]},
"error": true
}
]