File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,42 @@ func TestInstantiateContractValidation(t *testing.T) {
116116 },
117117 valid : false ,
118118 },
119+ "white space ending label" : {
120+ msg : MsgInstantiateContract {
121+ Sender : goodAddress ,
122+ CodeID : firstCodeID ,
123+ Label : "foo " ,
124+ Msg : []byte ("{}" ),
125+ },
126+ valid : false ,
127+ },
128+ "non printable chars ending label" : {
129+ msg : MsgInstantiateContract {
130+ Sender : goodAddress ,
131+ CodeID : firstCodeID ,
132+ Label : "foo\v " ,
133+ Msg : []byte ("{}" ),
134+ },
135+ valid : false ,
136+ },
137+ "non printable chars in label" : {
138+ msg : MsgInstantiateContract {
139+ Sender : goodAddress ,
140+ CodeID : firstCodeID ,
141+ Label : "f\v oo" ,
142+ Msg : []byte ("{}" ),
143+ },
144+ valid : false ,
145+ },
146+ "non printable chars beginning label" : {
147+ msg : MsgInstantiateContract {
148+ Sender : goodAddress ,
149+ CodeID : firstCodeID ,
150+ Label : "\v foo" ,
151+ Msg : []byte ("{}" ),
152+ },
153+ valid : false ,
154+ },
119155 "label too long" : {
120156 msg : MsgInstantiateContract {
121157 Sender : goodAddress ,
Original file line number Diff line number Diff line change 44 "fmt"
55 "net/url"
66 "strings"
7+ "unicode"
78
89 "github.com/distribution/reference"
910
@@ -45,6 +46,15 @@ func ValidateLabel(label string) error {
4546 if label != strings .TrimSpace (label ) {
4647 return ErrInvalid .Wrap ("label must not start/end with whitespaces" )
4748 }
49+ labelWithPrintableCharsOnly := strings .Map (func (r rune ) rune {
50+ if unicode .IsPrint (r ) {
51+ return r
52+ }
53+ return - 1
54+ }, label )
55+ if label != labelWithPrintableCharsOnly {
56+ return ErrInvalid .Wrap ("label must have printable characters only" )
57+ }
4858 return nil
4959}
5060
You can’t perform that action at this time.
0 commit comments