Commit 33e1560d authored by Taylor Otwell's avatar Taylor Otwell Committed by Matt Holt

httpserver: Add not_starts_with condition. (#1687)

* Add not_starts_with condition.

This adds the opposite of the starts_with condition, to check if a
given string does not start with another string.

* Correct white space problems
parent a5eb5522
...@@ -50,6 +50,7 @@ const ( ...@@ -50,6 +50,7 @@ const (
hasOp = "has" hasOp = "has"
notHasOp = "not_has" notHasOp = "not_has"
startsWithOp = "starts_with" startsWithOp = "starts_with"
notStartsWithOp = "not_starts_with"
endsWithOp = "ends_with" endsWithOp = "ends_with"
matchOp = "match" matchOp = "match"
notMatchOp = "not_match" notMatchOp = "not_match"
...@@ -68,6 +69,7 @@ var ifConditions = map[string]ifCondition{ ...@@ -68,6 +69,7 @@ var ifConditions = map[string]ifCondition{
hasOp: hasFunc, hasOp: hasFunc,
notHasOp: notHasFunc, notHasOp: notHasFunc,
startsWithOp: startsWithFunc, startsWithOp: startsWithFunc,
notStartsWithOp: notStartsWithFunc,
endsWithOp: endsWithFunc, endsWithOp: endsWithFunc,
matchOp: matchFunc, matchOp: matchFunc,
notMatchOp: notMatchFunc, notMatchOp: notMatchFunc,
...@@ -103,6 +105,12 @@ func startsWithFunc(a, b string) bool { ...@@ -103,6 +105,12 @@ func startsWithFunc(a, b string) bool {
return strings.HasPrefix(a, b) return strings.HasPrefix(a, b)
} }
// notStartsWithFunc is condition for NotStartsWith operator.
// It checks if b is not a prefix of a.
func notStartsWithFunc(a, b string) bool {
return !strings.HasPrefix(a, b)
}
// endsWithFunc is condition for EndsWith operator. // endsWithFunc is condition for EndsWith operator.
// It checks if b is a suffix of a. // It checks if b is a suffix of a.
func endsWithFunc(a, b string) bool { func endsWithFunc(a, b string) bool {
......
...@@ -32,6 +32,9 @@ func TestConditions(t *testing.T) { ...@@ -32,6 +32,9 @@ func TestConditions(t *testing.T) {
{"bab starts_with bb", false}, {"bab starts_with bb", false},
{"bab starts_with ba", true}, {"bab starts_with ba", true},
{"bab starts_with bab", true}, {"bab starts_with bab", true},
{"bab not_starts_with bb", true},
{"bab not_starts_with ba", false},
{"bab not_starts_with bab", false},
{"bab ends_with bb", false}, {"bab ends_with bb", false},
{"bab ends_with bab", true}, {"bab ends_with bab", true},
{"bab ends_with ab", true}, {"bab ends_with ab", true},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment