Skip to content

Commit

Permalink
fix: matcher.Match panic on nil *url.URL (#485)
Browse files Browse the repository at this point in the history
Closes #484
  • Loading branch information
err0r500 authored Jul 29, 2020
1 parent 0b74414 commit ab27dda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rule/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func TestMatcher(t *testing.T) {
assert.NotEmpty(t, got.matchingEngine.Checksum())
})

t.Run("case=nil url", func(t *testing.T) {
_, err := matcher.Match(context.Background(), "GET", nil)
require.Error(t, err)
})

require.NoError(t, matcher.Set(context.Background(), testRules[1:]))

t.Run("case=updated", func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions rule/repository_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (m *RepositoryMemory) Set(ctx context.Context, rules []Rule) error {
}

func (m *RepositoryMemory) Match(_ context.Context, method string, u *url.URL) (*Rule, error) {
if u == nil {
return nil, errors.WithStack(errors.New("nil URL provided"))
}

m.Lock()
defer m.Unlock()

Expand Down

0 comments on commit ab27dda

Please sign in to comment.