Skip to content

Commit

Permalink
Fix #780 which results duplicated query params
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysitu committed Oct 24, 2018
1 parent b2659f2 commit d4f7488
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/matching/query_matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ func QueryMatching(requestMatcher models.RequestMatcher, toMatch map[string][]st
}
}

lowercaseKeyMap := make(map[string][]string)
for key, value := range toMatch {
toMatch[strings.ToLower(key)] = value
lowercaseKeyMap[strings.ToLower(key)] = value
}

for matcherQueryKey, matcherQueryValue := range *requestMatcher.Query {
matcherHeaderValueMatched := false

toMatchQueryValues, found := toMatch[strings.ToLower(matcherQueryKey)]
toMatchQueryValues, found := lowercaseKeyMap[strings.ToLower(matcherQueryKey)]
if !found {
matched = false
continue
Expand Down
23 changes: 23 additions & 0 deletions core/matching/query_matching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,26 @@ func Test_QueryMatching(t *testing.T) {
}

}

func Test_QueryMatching_ShouldNotModifySourceQueries(t *testing.T) {
RegisterTestingT(t)

toMatch := map[string][]string{
"urlPattern": {"test-(.+).com"},
}

result := matching.QueryMatching(models.RequestMatcher{
Query: &models.QueryRequestFieldMatchers{
"urlPattern": {
{
Matcher: matchers.Glob,
Value: "test-(.+).com",
},
},
},
}, toMatch)

Expect(result.Matched).To(BeTrue())
Expect(len(toMatch)).To(Equal(1))
Expect(toMatch["urlPattern"]).To(Equal([]string{"test-(.+).com"}))
}

0 comments on commit d4f7488

Please sign in to comment.