Allow !~= for website/uri
This commit is contained in:
@@ -19,9 +19,11 @@ var andRe = regexp.MustCompile(`(?i)\s+and\s+`)
|
||||
//
|
||||
// status=200 status!=200 status>=400 status>400 status<=500 status<500
|
||||
// website=example.com — exact match
|
||||
// website~=gouda.* — RE2 regex
|
||||
// website~=gouda.* — RE2 regex match
|
||||
// website!~=gouda.* — RE2 regex exclusion
|
||||
// uri=/api/v1/ — exact match
|
||||
// uri~=^/api/.* — RE2 regex
|
||||
// uri~=^/api/.* — RE2 regex match
|
||||
// uri!~=^/ct/.* — RE2 regex exclusion
|
||||
// prefix=1.2.3.0/24 — exact match
|
||||
//
|
||||
// Values may be enclosed in double or single quotes.
|
||||
@@ -57,6 +59,8 @@ func applyTerm(term string, fs *filterState) error {
|
||||
|
||||
var op, value string
|
||||
switch {
|
||||
case strings.HasPrefix(rest, "!~="):
|
||||
op, value = "!~=", rest[3:]
|
||||
case strings.HasPrefix(rest, "~="):
|
||||
op, value = "~=", rest[2:]
|
||||
case strings.HasPrefix(rest, "!="):
|
||||
@@ -96,8 +100,10 @@ func applyTerm(term string, fs *filterState) error {
|
||||
fs.Website = value
|
||||
case "~=":
|
||||
fs.WebsiteRe = value
|
||||
case "!~=":
|
||||
fs.WebsiteReNeg = value
|
||||
default:
|
||||
return fmt.Errorf("website only supports = and ~=, not %q", op)
|
||||
return fmt.Errorf("website only supports =, ~=, and !~=, not %q", op)
|
||||
}
|
||||
case "uri":
|
||||
switch op {
|
||||
@@ -105,8 +111,10 @@ func applyTerm(term string, fs *filterState) error {
|
||||
fs.URI = value
|
||||
case "~=":
|
||||
fs.URIRe = value
|
||||
case "!~=":
|
||||
fs.URIReNeg = value
|
||||
default:
|
||||
return fmt.Errorf("uri only supports = and ~=, not %q", op)
|
||||
return fmt.Errorf("uri only supports =, ~=, and !~=, not %q", op)
|
||||
}
|
||||
case "prefix":
|
||||
if op != "=" {
|
||||
@@ -164,6 +172,9 @@ func FilterExprString(f filterState) string {
|
||||
if f.WebsiteRe != "" {
|
||||
parts = append(parts, "website~="+quoteMaybe(f.WebsiteRe))
|
||||
}
|
||||
if f.WebsiteReNeg != "" {
|
||||
parts = append(parts, "website!~="+quoteMaybe(f.WebsiteReNeg))
|
||||
}
|
||||
if f.Prefix != "" {
|
||||
parts = append(parts, "prefix="+quoteMaybe(f.Prefix))
|
||||
}
|
||||
@@ -173,6 +184,9 @@ func FilterExprString(f filterState) string {
|
||||
if f.URIRe != "" {
|
||||
parts = append(parts, "uri~="+quoteMaybe(f.URIRe))
|
||||
}
|
||||
if f.URIReNeg != "" {
|
||||
parts = append(parts, "uri!~="+quoteMaybe(f.URIReNeg))
|
||||
}
|
||||
if f.Status != "" {
|
||||
parts = append(parts, statusTermStr(f.Status))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user