Skip to content

Commit dc081d1

Browse files
authored
Fix expansion of @RequestParam empty lists (OpenFeign#1200)
* Add list tests to QueryTemplateTest * Make expandIterable() return empty string if unresolved * Rename new tests to fit existing tests * Format code * Fix newlines
1 parent 37d973c commit dc081d1

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

core/src/main/java/feign/template/Expressions.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2019 The Feign Authors
2+
* Copyright 2012-2020 The Feign Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
* in compliance with the License. You may obtain a copy of the License at
@@ -152,11 +152,6 @@ private String expandIterable(Iterable<?> values) {
152152
}
153153
}
154154

155-
if (result.length() == 0) {
156-
/* completely unresolved */
157-
return null;
158-
}
159-
160155
/* return the expanded value */
161156
return result.toString();
162157
}

core/src/test/java/feign/template/QueryTemplateTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ public void templateToQueryString() {
3030
assertThat(template.toString()).isEqualToIgnoringCase("name=Bob&name=James&name=Jason");
3131
}
3232

33+
@Test
34+
public void expandEmptyCollection() {
35+
QueryTemplate template =
36+
QueryTemplate.create("people", Collections.singletonList("{people}"), Util.UTF_8);
37+
String expanded = template.expand(Collections.singletonMap("people", Collections.emptyList()));
38+
assertThat(expanded).isEqualToIgnoringCase("people=");
39+
}
40+
41+
@Test
42+
public void expandCollection() {
43+
QueryTemplate template =
44+
QueryTemplate.create("people", Collections.singletonList("{people}"), Util.UTF_8);
45+
String expanded =
46+
template.expand(Collections.singletonMap("people", Arrays.asList("Bob", "James", "Jason")));
47+
assertThat(expanded).isEqualToIgnoringCase("people=Bob&people=James&people=Jason");
48+
}
49+
3350
@Test
3451
public void expandCollectionWithBlanks() {
3552
QueryTemplate template =

0 commit comments

Comments
 (0)