File tree 2 files changed +9
-4
lines changed 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ var SECRET_KEY string
21
21
22
22
var version = "6.0.6"
23
23
24
- var userPattern = regexp .MustCompile ("^[:word: ]*$" )
24
+ var userPattern = regexp .MustCompile ("^[a-zA-Z0-9_.- ]*$" )
25
25
26
26
// user should be [A-Za-z0-9]*
27
27
func SetUser (user string ) error {
Original file line number Diff line number Diff line change @@ -8,17 +8,22 @@ import (
8
8
func TestUA (t * testing.T ) {
9
9
err := SetUser ("" )
10
10
if err != nil {
11
- t .Fatal (err )
11
+ t .Fatal ("expect no error" )
12
12
}
13
13
err = SetUser ("错误的UA" )
14
14
if err == nil {
15
15
t .Fatal ("expect an invalid ua format" )
16
16
}
17
+ err = SetUser ("Test0-_." )
18
+ if err != nil {
19
+ t .Fatal ("expect no error" )
20
+ }
17
21
}
18
22
19
23
func TestFormat (t * testing.T ) {
20
- v := formatUserAgent ("test" )
21
- if ! strings .Contains (v , "test" ) {
24
+ str := "tesT0.-_"
25
+ v := formatUserAgent (str )
26
+ if ! strings .Contains (v , str ) {
22
27
t .Fatal ("should include user" )
23
28
}
24
29
if ! strings .HasPrefix (v , "QiniuGo/" + version ) {
You can’t perform that action at this time.
0 commit comments