Skip to content

Commit d4f7488

Browse files
committed
Fix #780 which results duplicated query params
1 parent b2659f2 commit d4f7488

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

core/matching/query_matching.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ func QueryMatching(requestMatcher models.RequestMatcher, toMatch map[string][]st
3131
}
3232
}
3333

34+
lowercaseKeyMap := make(map[string][]string)
3435
for key, value := range toMatch {
35-
toMatch[strings.ToLower(key)] = value
36+
lowercaseKeyMap[strings.ToLower(key)] = value
3637
}
3738

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

41-
toMatchQueryValues, found := toMatch[strings.ToLower(matcherQueryKey)]
42+
toMatchQueryValues, found := lowercaseKeyMap[strings.ToLower(matcherQueryKey)]
4243
if !found {
4344
matched = false
4445
continue

core/matching/query_matching_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,26 @@ func Test_QueryMatching(t *testing.T) {
182182
}
183183

184184
}
185+
186+
func Test_QueryMatching_ShouldNotModifySourceQueries(t *testing.T) {
187+
RegisterTestingT(t)
188+
189+
toMatch := map[string][]string{
190+
"urlPattern": {"test-(.+).com"},
191+
}
192+
193+
result := matching.QueryMatching(models.RequestMatcher{
194+
Query: &models.QueryRequestFieldMatchers{
195+
"urlPattern": {
196+
{
197+
Matcher: matchers.Glob,
198+
Value: "test-(.+).com",
199+
},
200+
},
201+
},
202+
}, toMatch)
203+
204+
Expect(result.Matched).To(BeTrue())
205+
Expect(len(toMatch)).To(Equal(1))
206+
Expect(toMatch["urlPattern"]).To(Equal([]string{"test-(.+).com"}))
207+
}

0 commit comments

Comments
 (0)