Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
55f69fd7
Commit
55f69fd7
authored
Dec 31, 2015
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add not_has and not_match conditions.
parent
4636ca10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
middleware/rewrite/condition.go
middleware/rewrite/condition.go
+19
-0
middleware/rewrite/condition_test.go
middleware/rewrite/condition_test.go
+16
-0
No files found.
middleware/rewrite/condition.go
View file @
55f69fd7
...
...
@@ -14,9 +14,11 @@ const (
Is
=
"is"
Not
=
"not"
Has
=
"has"
NotHas
=
"not_has"
StartsWith
=
"starts_with"
EndsWith
=
"ends_with"
Match
=
"match"
NotMatch
=
"not_match"
)
func
operatorError
(
operator
string
)
error
{
...
...
@@ -34,9 +36,11 @@ var conditions = map[string]condition{
Is
:
isFunc
,
Not
:
notFunc
,
Has
:
hasFunc
,
NotHas
:
notHasFunc
,
StartsWith
:
startsWithFunc
,
EndsWith
:
endsWithFunc
,
Match
:
matchFunc
,
NotMatch
:
notMatchFunc
,
}
// isFunc is condition for Is operator.
...
...
@@ -57,6 +61,12 @@ func hasFunc(a, b string) bool {
return
strings
.
Contains
(
a
,
b
)
}
// notHasFunc is condition for NotHas operator.
// It checks if b is not a substring of a.
func
notHasFunc
(
a
,
b
string
)
bool
{
return
!
strings
.
Contains
(
a
,
b
)
}
// startsWithFunc is condition for StartsWith operator.
// It checks if b is a prefix of a.
func
startsWithFunc
(
a
,
b
string
)
bool
{
...
...
@@ -71,11 +81,20 @@ func endsWithFunc(a, b string) bool {
// matchFunc is condition for Match operator.
// It does regexp matching of a against pattern in b
// and returns if they match.
func
matchFunc
(
a
,
b
string
)
bool
{
matched
,
_
:=
regexp
.
MatchString
(
b
,
a
)
return
matched
}
// notMatchFunc is condition for NotMatch operator.
// It does regexp matching of a against pattern in b
// and returns if they do not match.
func
notMatchFunc
(
a
,
b
string
)
bool
{
matched
,
_
:=
regexp
.
MatchString
(
b
,
a
)
return
!
matched
}
// If is statement for a rewrite condition.
type
If
struct
{
A
string
...
...
middleware/rewrite/condition_test.go
View file @
55f69fd7
...
...
@@ -20,6 +20,11 @@ func TestConditions(t *testing.T) {
{
"ba has b"
,
true
},
{
"bab has b"
,
true
},
{
"bab has bb"
,
false
},
{
"a not_has a"
,
false
},
{
"a not_has b"
,
true
},
{
"ba not_has b"
,
false
},
{
"bab not_has b"
,
false
},
{
"bab not_has bb"
,
true
},
{
"bab starts_with bb"
,
false
},
{
"bab starts_with ba"
,
true
},
{
"bab starts_with bab"
,
true
},
...
...
@@ -37,6 +42,17 @@ func TestConditions(t *testing.T) {
{
"b0a match b[a-z]"
,
false
},
{
"b0a match b[a-z]+"
,
false
},
{
"b0a match b[a-z0-9]+"
,
true
},
{
"a not_match *"
,
true
},
{
"a not_match a"
,
false
},
{
"a not_match .*"
,
false
},
{
"a not_match a.*"
,
false
},
{
"a not_match b.*"
,
true
},
{
"ba not_match b.*"
,
false
},
{
"ba not_match b[a-z]"
,
false
},
{
"b0 not_match b[a-z]"
,
true
},
{
"b0a not_match b[a-z]"
,
true
},
{
"b0a not_match b[a-z]+"
,
true
},
{
"b0a not_match b[a-z0-9]+"
,
false
},
}
for
i
,
test
:=
range
tests
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment