diff --git a/core/matching/query_matching.go b/core/matching/query_matching.go index 731a30625..8b890af06 100644 --- a/core/matching/query_matching.go +++ b/core/matching/query_matching.go @@ -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 diff --git a/core/matching/query_matching_test.go b/core/matching/query_matching_test.go index b56e39d14..c44448cc4 100644 --- a/core/matching/query_matching_test.go +++ b/core/matching/query_matching_test.go @@ -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"})) +}