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 @@ -115,6 +115,42 @@ func TestInstantiateContractValidation(t *testing.T) {
115115 },
116116 valid : false ,
117117 },
118+ "white space ending label" : {
119+ msg : MsgInstantiateContract {
120+ Sender : goodAddress ,
121+ CodeID : firstCodeID ,
122+ Label : "foo " ,
123+ Msg : []byte ("{}" ),
124+ },
125+ valid : false ,
126+ },
127+ "non printable chars ending label" : {
128+ msg : MsgInstantiateContract {
129+ Sender : goodAddress ,
130+ CodeID : firstCodeID ,
131+ Label : "foo\v " ,
132+ Msg : []byte ("{}" ),
133+ },
134+ valid : false ,
135+ },
136+ "non printable chars in label" : {
137+ msg : MsgInstantiateContract {
138+ Sender : goodAddress ,
139+ CodeID : firstCodeID ,
140+ Label : "f\v oo" ,
141+ Msg : []byte ("{}" ),
142+ },
143+ valid : false ,
144+ },
145+ "non printable chars beginning label" : {
146+ msg : MsgInstantiateContract {
147+ Sender : goodAddress ,
148+ CodeID : firstCodeID ,
149+ Label : "\v foo" ,
150+ Msg : []byte ("{}" ),
151+ },
152+ valid : false ,
153+ },
118154 "label too long" : {
119155 msg : MsgInstantiateContract {
120156 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/docker/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