Move many PR's change here since the original authors are responseless

This commit is contained in:
Ming Deng 2020-06-23 21:18:58 +08:00
parent 96658121dc
commit 3ce68d6a30
5 changed files with 73 additions and 43 deletions

View File

@ -420,9 +420,9 @@ func newAppConfig(appConfigProvider, appConfigPath string) (*beegoAppConfig, err
func (b *beegoAppConfig) Set(key, val string) error {
if err := b.innerConfig.Set(BConfig.RunMode+"::"+key, val); err != nil {
return err
return b.innerConfig.Set(key, val)
}
return b.innerConfig.Set(key, val)
return nil
}
func (b *beegoAppConfig) String(key string) string {

View File

@ -129,8 +129,9 @@ func (fp *FileProvider) SessionInit(maxlifetime int64, savePath string) error {
// if file is not exist, create it.
// the file path is generated from sid string.
func (fp *FileProvider) SessionRead(sid string) (Store, error) {
if strings.ContainsAny(sid, "./") {
return nil, nil
invalidChars := "./"
if strings.ContainsAny(sid, invalidChars) {
return nil, errors.New("the sid shouldn't have following characters: " + invalidChars)
}
if len(sid) < 2 {
return nil, errors.New("length of the sid is less than 2")

View File

@ -33,7 +33,7 @@ type bounds struct {
// The bounds for each field.
var (
AdminTaskList map[string]Tasker
taskLock sync.Mutex
taskLock sync.RWMutex
stop chan bool
changed chan bool
isstart bool
@ -408,7 +408,10 @@ func run() {
}
for {
// we only use RLock here because NewMapSorter copy the reference, do not change any thing
taskLock.RLock()
sortList := NewMapSorter(AdminTaskList)
taskLock.RUnlock()
sortList.Sort()
var effective time.Time
if len(AdminTaskList) == 0 || sortList.Vals[0].GetNext().IsZero() {
@ -432,9 +435,11 @@ func run() {
continue
case <-changed:
now = time.Now().Local()
taskLock.Lock()
for _, t := range AdminTaskList {
t.SetNext(now)
}
taskLock.Unlock()
continue
case <-stop:
return

View File

@ -253,44 +253,68 @@ func TestBase64(t *testing.T) {
func TestMobile(t *testing.T) {
valid := Validation{}
if valid.Mobile("19800008888", "mobile").Ok {
t.Error("\"19800008888\" is a valid mobile phone number should be false")
validMobiles := []string{
"19800008888",
"18800008888",
"18000008888",
"8618300008888",
"+8614700008888",
"17300008888",
"+8617100008888",
"8617500008888",
"8617400008888",
"16200008888",
"16500008888",
"16600008888",
"16700008888",
"13300008888",
"14900008888",
"15300008888",
"17300008888",
"17700008888",
"18000008888",
"18900008888",
"19100008888",
"19900008888",
"19300008888",
"13000008888",
"13100008888",
"13200008888",
"14500008888",
"15500008888",
"15600008888",
"16600008888",
"17100008888",
"17500008888",
"17600008888",
"18500008888",
"18600008888",
"13400008888",
"13500008888",
"13600008888",
"13700008888",
"13800008888",
"13900008888",
"14700008888",
"15000008888",
"15100008888",
"15200008888",
"15800008888",
"15900008888",
"17200008888",
"17800008888",
"18200008888",
"18300008888",
"18400008888",
"18700008888",
"18800008888",
"19800008888",
}
if !valid.Mobile("18800008888", "mobile").Ok {
t.Error("\"18800008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("18000008888", "mobile").Ok {
t.Error("\"18000008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("8618300008888", "mobile").Ok {
t.Error("\"8618300008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("+8614700008888", "mobile").Ok {
t.Error("\"+8614700008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("17300008888", "mobile").Ok {
t.Error("\"17300008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("+8617100008888", "mobile").Ok {
t.Error("\"+8617100008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("8617500008888", "mobile").Ok {
t.Error("\"8617500008888\" is a valid mobile phone number should be true")
}
if valid.Mobile("8617400008888", "mobile").Ok {
t.Error("\"8617400008888\" is a valid mobile phone number should be false")
}
if !valid.Mobile("16200008888", "mobile").Ok {
t.Error("\"16200008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("16500008888", "mobile").Ok {
t.Error("\"16500008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("16600008888", "mobile").Ok {
t.Error("\"16600008888\" is a valid mobile phone number should be true")
}
if !valid.Mobile("16700008888", "mobile").Ok {
t.Error("\"16700008888\" is a valid mobile phone number should be true")
for _, m := range validMobiles {
if !valid.Mobile(m, "mobile").Ok {
t.Error(m + " is a valid mobile phone number should be true")
}
}
}

View File

@ -632,7 +632,7 @@ func (b Base64) GetLimitValue() interface{} {
}
// just for chinese mobile phone number
var mobilePattern = regexp.MustCompile(`^((\+86)|(86))?(1(([35][0-9])|[8][0-9]|[7][01356789]|[4][579]|[6][2567]))\d{8}$`)
var mobilePattern = regexp.MustCompile(`^((\+86)|(86))?1([356789][0-9]|4[579]|6[67]|7[0135678]|9[189])[0-9]{8}$`)
// Mobile check struct
type Mobile struct {