From d4f7488f709351dafb150292b4744a01d9a6cd91 Mon Sep 17 00:00:00 2001 From: Tommy Situ Date: Tue, 23 Oct 2018 21:56:21 +0100 Subject: [PATCH] Fix #780 which results duplicated query params --- core/matching/query_matching.go | 5 +++-- core/matching/query_matching_test.go | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) 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"})) +}