Skip to content

Commit

Permalink
rule: Ignore query parameters when matching url in rules. (#139)
Browse files Browse the repository at this point in the history
Signed-off-by: Stanislav Zapolsky <stszap@gmail.com>
  • Loading branch information
stszap authored and aeneasr committed Dec 3, 2018
1 parent ab5240e commit 07eb99b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package rule

import (
"encoding/json"
"fmt"
"hash/crc32"
"net/url"
"regexp"
Expand Down Expand Up @@ -124,7 +125,7 @@ func (r *Rule) IsMatching(method string, u *url.URL) error {
return errors.WithStack(err)
}

if !c.MatchString(u.String()) {
if !c.MatchString(fmt.Sprintf("%s://%s%s", u.Scheme, u.Host, u.Path)) {
return errors.Errorf("rule %s does not match URL %s", r.ID, u)
}

Expand Down
1 change: 1 addition & 0 deletions rule/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ func TestRule(t *testing.T) {
}

assert.NoError(t, r.IsMatching("DELETE", mustParse(t, "https://localhost/users/1234")))
assert.NoError(t, r.IsMatching("DELETE", mustParse(t, "https://localhost/users/1234?key=value&key1=value1")))
assert.Error(t, r.IsMatching("DELETE", mustParse(t, "https://localhost/users/abcd")))
}

0 comments on commit 07eb99b

Please sign in to comment.