diff --git a/x/wasm/types/tx_test.go b/x/wasm/types/tx_test.go index 4533991324..1045b95028 100644 --- a/x/wasm/types/tx_test.go +++ b/x/wasm/types/tx_test.go @@ -125,7 +125,7 @@ func TestInstantiateContractValidation(t *testing.T) { }, valid: false, }, - "non printable chars in label": { + "non printable chars ending label": { msg: MsgInstantiateContract{ Sender: goodAddress, CodeID: firstCodeID, @@ -134,6 +134,24 @@ func TestInstantiateContractValidation(t *testing.T) { }, valid: false, }, + "non printable chars in label": { + msg: MsgInstantiateContract{ + Sender: goodAddress, + CodeID: firstCodeID, + Label: "f\voo", + Msg: []byte("{}"), + }, + valid: false, + }, + "non printable chars beginning label": { + msg: MsgInstantiateContract{ + Sender: goodAddress, + CodeID: firstCodeID, + Label: "\vfoo", + Msg: []byte("{}"), + }, + valid: false, + }, "label too long": { msg: MsgInstantiateContract{ Sender: goodAddress, diff --git a/x/wasm/types/validation.go b/x/wasm/types/validation.go index b940a901cc..bd67e3bc26 100644 --- a/x/wasm/types/validation.go +++ b/x/wasm/types/validation.go @@ -46,11 +46,14 @@ func ValidateLabel(label string) error { if label != strings.TrimSpace(label) { return ErrInvalid.Wrap("label must not start/end with whitespaces") } - labelWithoutNonPrintableChars := strings.TrimFunc(label, func(r rune) bool { - return !unicode.IsGraphic(r) - }) - if label != labelWithoutNonPrintableChars { - return ErrInvalid.Wrap("label must not have non printable characters") + labelWithPrintableCharsOnly := strings.Map(func(r rune) rune { + if unicode.IsPrint(r) { + return r + } + return -1 + }, label) + if label != labelWithPrintableCharsOnly { + return ErrInvalid.Wrap("label must have printable characters only") } return nil }