Feat : Trimmed label to prevent white spaces (#1412)

* Merge pull request #1397 from CosmWasm/ext_wasmibctesting

Decouple testing from app with an interface

* Feat : Trimmed label to prevent white spaces

* Fix: Made required nit changes

* Added test files to validate untrimmed labels
This commit is contained in:
ruthishvitwit
2023-05-26 16:36:33 +05:30
committed by GitHub
parent b0bfcc43d0
commit e563a10cfa
2 changed files with 10 additions and 0 deletions

View File

@@ -340,6 +340,12 @@ func TestValidateInstantiateContract2Proposal(t *testing.T) {
}), }),
expErr: true, expErr: true,
}, },
"untrimmed label ": {
src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) {
p.Label = " label "
}),
expErr: true,
},
"init funds negative": { "init funds negative": {
src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) { src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) {
p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(-1)}} p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(-1)}}

View File

@@ -3,6 +3,7 @@ package types
import ( import (
"fmt" "fmt"
"net/url" "net/url"
"strings"
errorsmod "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
@@ -40,6 +41,9 @@ func ValidateLabel(label string) error {
if len(label) > MaxLabelSize { if len(label) > MaxLabelSize {
return ErrLimit.Wrapf("cannot be longer than %d characters", MaxLabelSize) return ErrLimit.Wrapf("cannot be longer than %d characters", MaxLabelSize)
} }
if label != strings.TrimSpace(label) {
return ErrInvalid.Wrap("label must not start/end with whitespaces")
}
return nil return nil
} }