WAF增加包含任一字符串、包含所有字符串操作符

This commit is contained in:
刘祥超
2023-01-06 20:07:15 +08:00
parent 8a8881ac47
commit a17878f5b2
5 changed files with 74 additions and 10 deletions

View File

@@ -8,17 +8,19 @@ import (
)
type StringList struct {
ValueMap map[string]zero.Zero
ValueMap map[string]zero.Zero
CaseInsensitive bool
}
func NewStringList() *StringList {
func NewStringList(caseInsensitive bool) *StringList {
return &StringList{
ValueMap: map[string]zero.Zero{},
ValueMap: map[string]zero.Zero{},
CaseInsensitive: caseInsensitive,
}
}
func ParseStringList(v string) *StringList {
var list = NewStringList()
func ParseStringList(v string, caseInsensitive bool) *StringList {
var list = NewStringList(caseInsensitive)
if len(v) == 0 {
return list
}
@@ -34,6 +36,9 @@ func ParseStringList(v string) *StringList {
for _, value := range values {
value = strings.TrimSpace(value)
if len(value) > 0 {
if caseInsensitive {
value = strings.ToLower(value)
}
list.ValueMap[value] = zero.Zero{}
}
}
@@ -42,6 +47,9 @@ func ParseStringList(v string) *StringList {
}
func (this *StringList) Contains(f string) bool {
if this.CaseInsensitive {
f = strings.ToLower(f)
}
_, ok := this.ValueMap[f]
return ok
}