Skip to content

Commit e46ab68

Browse files
koiuoadriancole
authored andcommitted
Clears query param with unsafe characters in name (OpenFeign#409)
1 parent 464a2b1 commit e46ab68

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎core/src/main/java/feign/RequestTemplate.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,14 @@ public String url() {
306306
* @see #queries()
307307
*/
308308
public RequestTemplate query(String name, String... values) {
309-
queries.remove(checkNotNull(name, "name"));
309+
String encodedName = encodeIfNotVariable(checkNotNull(name, "name"));
310+
queries.remove(encodedName);
310311
if (values != null && values.length > 0 && values[0] != null) {
311312
ArrayList<String> encoded = new ArrayList<String>();
312313
for (String value : values) {
313314
encoded.add(encodeIfNotVariable(value));
314315
}
315-
this.queries.put(encodeIfNotVariable(name), encoded);
316+
this.queries.put(encodedName, encoded);
316317
}
317318
return this;
318319
}

‎core/src/test/java/feign/RequestTemplateTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,15 @@ public void uriStuffedIntoMethod() throws Exception {
332332

333333
new RequestTemplate().method("/path?queryParam={queryParam}");
334334
}
335+
336+
@Test
337+
public void encodedQueryClearedOnNull() throws Exception {
338+
RequestTemplate template = new RequestTemplate();
339+
340+
template.query("param[]", "value");
341+
assertThat(template).hasQueries(entry("param[]", asList("value")));
342+
343+
template.query("param[]", (String[]) null);
344+
assertThat(template.queries()).isEmpty();
345+
}
335346
}

0 commit comments

Comments
 (0)