Skip to content

Commit

Permalink
Feat : Trimmed label to prevent white spaces (#1412)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ruthishvitwit authored May 26, 2023
1 parent b0bfcc4 commit e563a10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions x/wasm/types/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ func TestValidateInstantiateContract2Proposal(t *testing.T) {
}),
expErr: true,
},
"untrimmed label ": {
src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) {
p.Label = " label "
}),
expErr: true,
},
"init funds negative": {
src: InstantiateContract2ProposalFixture(func(p *InstantiateContract2Proposal) {
p.Funds = sdk.Coins{{Denom: "foo", Amount: sdk.NewInt(-1)}}
Expand Down
4 changes: 4 additions & 0 deletions x/wasm/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"fmt"
"net/url"
"strings"

errorsmod "cosmossdk.io/errors"
"github.com/docker/distribution/reference"
Expand Down Expand Up @@ -40,6 +41,9 @@ func ValidateLabel(label string) error {
if len(label) > 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
}

Expand Down

0 comments on commit e563a10

Please sign in to comment.