From e563a10cfac1c2ea744f5694641de6ab59183694 Mon Sep 17 00:00:00 2001 From: ruthishvitwit <122080147+ruthishvitwit@users.noreply.github.com> Date: Fri, 26 May 2023 16:36:33 +0530 Subject: [PATCH] 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 --- x/wasm/types/proposal_test.go | 6 ++++++ x/wasm/types/validation.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/x/wasm/types/proposal_test.go b/x/wasm/types/proposal_test.go index 8952f8cf..dc2bc516 100644 --- a/x/wasm/types/proposal_test.go +++ b/x/wasm/types/proposal_test.go @@ -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)}} diff --git a/x/wasm/types/validation.go b/x/wasm/types/validation.go index 38da21e9..b954c4f8 100644 --- a/x/wasm/types/validation.go +++ b/x/wasm/types/validation.go @@ -3,6 +3,7 @@ package types import ( "fmt" "net/url" + "strings" errorsmod "cosmossdk.io/errors" "github.com/docker/distribution/reference" @@ -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 }