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) {
116
116
},
117
117
valid : false ,
118
118
},
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
+ },
119
155
"label too long" : {
120
156
msg : MsgInstantiateContract {
121
157
Sender : goodAddress ,
Original file line number Diff line number Diff line change 4
4
"fmt"
5
5
"net/url"
6
6
"strings"
7
+ "unicode"
7
8
8
9
"github.com/distribution/reference"
9
10
@@ -45,6 +46,15 @@ func ValidateLabel(label string) error {
45
46
if label != strings .TrimSpace (label ) {
46
47
return ErrInvalid .Wrap ("label must not start/end with whitespaces" )
47
48
}
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
+ }
48
58
return nil
49
59
}
50
60
You can’t perform that action at this time.
0 commit comments