mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-26 06:56:35 +08:00
WAF增加包含任一字符串、包含所有字符串操作符
This commit is contained in:
@@ -3,5 +3,5 @@
|
||||
package values
|
||||
|
||||
func ParseIPList(v string) *StringList {
|
||||
return ParseStringList(v)
|
||||
return ParseStringList(v, false)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ func TestParseStringList(t *testing.T) {
|
||||
var a = assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
var list = values.ParseStringList("")
|
||||
var list = values.ParseStringList("", false)
|
||||
a.IsFalse(list.Contains("hello"))
|
||||
}
|
||||
|
||||
@@ -22,9 +22,22 @@ func TestParseStringList(t *testing.T) {
|
||||
world
|
||||
hi
|
||||
|
||||
people`)
|
||||
people`, false)
|
||||
a.IsTrue(list.Contains("hello"))
|
||||
a.IsFalse(list.Contains("hello1"))
|
||||
a.IsFalse(list.Contains("Hello"))
|
||||
a.IsTrue(list.Contains("hi"))
|
||||
}
|
||||
{
|
||||
var list = values.ParseStringList(`Hello
|
||||
|
||||
world
|
||||
hi
|
||||
|
||||
people`, true)
|
||||
a.IsTrue(list.Contains("hello"))
|
||||
a.IsTrue(list.Contains("Hello"))
|
||||
a.IsTrue(list.Contains("HELLO"))
|
||||
a.IsFalse(list.Contains("How"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user