Fix MakeRegexpArray handling empty strings

This commit is contained in:
Shiming Zhang 2021-03-02 17:53:00 +08:00
parent 4eca18b6b0
commit 63860270e3
2 changed files with 25 additions and 0 deletions

View File

@ -61,6 +61,9 @@ type FilterServer struct {
// MakeRegexpArray splits a comma separated list of regexps into an array of Regexp objects.
func MakeRegexpArray(str string) ([]*regexp.Regexp, error) {
if str == "" {
return []*regexp.Regexp{}, nil
}
parts := strings.Split(str, ",")
result := make([]*regexp.Regexp, len(parts))
for ix := range parts {

View File

@ -275,6 +275,28 @@ func TestAccept(t *testing.T) {
method: "PUT",
expectAccept: false,
},
{
name: "test23",
acceptPaths: DefaultPathAcceptRE,
rejectPaths: DefaultPathRejectRE,
acceptHosts: DefaultHostAcceptRE,
rejectMethods: DefaultMethodRejectRE,
path: "/api/v1/namespaces/default/pods/somepod/exec",
host: "localhost",
method: "POST",
expectAccept: false,
},
{
name: "test24",
acceptPaths: DefaultPathAcceptRE,
rejectPaths: "",
acceptHosts: DefaultHostAcceptRE,
rejectMethods: DefaultMethodRejectRE,
path: "/api/v1/namespaces/default/pods/somepod/exec",
host: "localhost",
method: "POST",
expectAccept: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {