From 313852793f47f30ddfbfc3aa1d20601c4c606138 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 27 Sep 2021 16:01:20 -0400 Subject: [PATCH] feat!: update Denom regex to support more DID characters (#9699) * feat!: support DID method-specific-id regex in denoms * udpate docs * add test case * update CHANGELOG.md * fix CHANGELOG.md * fix test * fix test --- CHANGELOG.md | 1 + types/coin.go | 4 ++-- types/coin_test.go | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c94e4923f9..ce410e404a6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -117,6 +117,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (cli) [\#9856](https://github.com/cosmos/cosmos-sdk/pull/9856) Overwrite `--sequence` and `--account-number` flags with default flag values when used with `offline=false` in `sign-batch` command. * (types) [\#10021](https://github.com/cosmos/cosmos-sdk/pull/10021) Speedup coins.AmountOf(), by removing many intermittent regex calls. * (rosetta) [\#10001](https://github.com/cosmos/cosmos-sdk/issues/10001) Add documentation for rosetta-cli dockerfile and rename folder for the rosetta-ci dockerfile +* [\#9699](https://github.com/cosmos/cosmos-sdk/pull/9699) Add `:`, `.`, `-`, and `_` as allowed characters in the default denom regular expression. ### Bug Fixes diff --git a/types/coin.go b/types/coin.go index 0546d5c63d1b..68cd7062505f 100644 --- a/types/coin.go +++ b/types/coin.go @@ -644,8 +644,8 @@ func (coins Coins) Sort() Coins { var ( // Denominations can be 3 ~ 128 characters long and support letters, followed by either - // a letter, a number or a separator ('/'). - reDnmString = `[a-zA-Z][a-zA-Z0-9/-]{2,127}` + // a letter, a number or a separator ('/', ':', '.', '_' or '-'). + reDnmString = `[a-zA-Z][a-zA-Z0-9/:._-]{2,127}` reDecAmt = `[[:digit:]]+(?:\.[[:digit:]]+)?|\.[[:digit:]]+` reSpc = `[[:space:]]*` reDnm *regexp.Regexp diff --git a/types/coin_test.go b/types/coin_test.go index 9a5d83fea9c3..9ee493aaa0b9 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -96,6 +96,7 @@ func (s *coinTestSuite) TestCoinIsValid() { {sdk.Coin{loremIpsum, sdk.OneInt()}, false}, {sdk.Coin{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.OneInt()}, true}, {sdk.Coin{"atOm", sdk.OneInt()}, true}, + {sdk.Coin{"x:y-z.1_2", sdk.OneInt()}, true}, {sdk.Coin{" ", sdk.OneInt()}, false}, } @@ -706,7 +707,7 @@ func (s *coinTestSuite) TestParseCoins() { {"2 3foo, 97 bar", false, nil}, // 3foo is invalid coin name {"11me coin, 12you coin", false, nil}, // no spaces in coin names {"1.2btc", true, sdk.Coins{{"btc", sdk.NewInt(1)}}}, // amount can be decimal, will get truncated - {"5foo:bar", false, nil}, // invalid separator + {"5foo:bar", true, sdk.Coins{{"foo:bar", sdk.NewInt(5)}}}, {"10atom10", true, sdk.Coins{{"atom10", sdk.NewInt(10)}}}, {"200transfer/channelToA/uatom", true, sdk.Coins{{"transfer/channelToA/uatom", sdk.NewInt(200)}}}, {"50ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", true, sdk.Coins{{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.NewInt(50)}}},