Skip to content

Commit

Permalink
Merge pull request #117 from qiniu/develop
Browse files Browse the repository at this point in the history
6.0.6 patch
  • Loading branch information
longbai committed Jun 30, 2014
2 parents 10ed8d0 + 04b4d13 commit 6ec0594
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var SECRET_KEY string

var version = "6.0.6"

var userPattern = regexp.MustCompile("^[:word:]*$")
var userPattern = regexp.MustCompile("^[a-zA-Z0-9_.-]*$")

// user should be [A-Za-z0-9]*
func SetUser(user string) error {
Expand Down
11 changes: 8 additions & 3 deletions conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import (
func TestUA(t *testing.T) {
err := SetUser("")
if err != nil {
t.Fatal(err)
t.Fatal("expect no error")
}
err = SetUser("错误的UA")
if err == nil {
t.Fatal("expect an invalid ua format")
}
err = SetUser("Test0-_.")
if err != nil {
t.Fatal("expect no error")
}
}

func TestFormat(t *testing.T) {
v := formatUserAgent("test")
if !strings.Contains(v, "test") {
str := "tesT0.-_"
v := formatUserAgent(str)
if !strings.Contains(v, str) {
t.Fatal("should include user")
}
if !strings.HasPrefix(v, "QiniuGo/"+version) {
Expand Down

0 comments on commit 6ec0594

Please sign in to comment.