Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat : Trimmed label to prevent white spaces #1412

Merged
merged 6 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions x/wasm/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ func (p InstantiateContractProposal) ValidateBasic() error {
if p.CodeID == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "code id is required")
}
//this code can be removed based on the preference between silent trimming the label or validating the label
ruthishvitwit marked this conversation as resolved.
Show resolved Hide resolved
if p.Label != strings.TrimSpace(p.Label) {
ruthishvitwit marked this conversation as resolved.
Show resolved Hide resolved
p.Label = strings.TrimSpace(p.Label)
}

if err := ValidateLabel(p.Label); err != nil {
return err
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.Wrapf("'%s'This label is not trimmed", label)
ruthishvitwit marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}

Expand Down