Skip to content

Commit 8263985

Browse files
muchnikspencergibb
authored andcommitted
Support nullable flag value in ShortcutConfigurable.ShortcutType#GATHER_LIST_TAIL_FLAG
Fixes gh-3049
1 parent b3acabf commit 8263985

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/ShortcutConfigurable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public Map<String, Object> normalize(Map<String, String> args, ShortcutConfigura
151151
// strip boolean flag if last entry is true or false
152152
int lastIdx = values.size() - 1;
153153
String lastValue = values.get(lastIdx);
154-
if (lastValue.equalsIgnoreCase("true") || lastValue.equalsIgnoreCase("false")) {
154+
if ("true".equalsIgnoreCase(lastValue) || "false".equalsIgnoreCase(lastValue) || lastValue == null) {
155155
values = values.subList(0, lastIdx);
156156
map.put(fieldOrder.get(1), getValue(parser, beanFactory, lastValue));
157157
}

spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/support/ShortcutConfigurableTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,32 @@ public ShortcutType shortcutType() {
182182
}
183183
}
184184

185+
@Test
186+
public void testNormalizeGatherListTailFlagFlagIsNull() {
187+
parser = new SpelExpressionParser();
188+
ShortcutConfigurable shortcutConfigurable = new ShortcutConfigurable() {
189+
@Override
190+
public List<String> shortcutFieldOrder() {
191+
return Arrays.asList("values", "flag");
192+
}
193+
194+
@Override
195+
public ShortcutType shortcutType() {
196+
return ShortcutType.GATHER_LIST_TAIL_FLAG;
197+
}
198+
};
199+
Map<String, String> args = new HashMap<>();
200+
args.put("1", "val0");
201+
args.put("2", "val1");
202+
args.put("3", "val2");
203+
args.put("4", null);
204+
Map<String, Object> map = ShortcutType.GATHER_LIST_TAIL_FLAG.normalize(args, shortcutConfigurable, parser,
205+
this.beanFactory);
206+
assertThat(map).isNotNull().containsKey("values");
207+
assertThat((List) map.get("values")).containsExactly("val0", "val1", "val2");
208+
assertThat(map.get("flag")).isNull();
209+
}
210+
185211
@SpringBootConfiguration
186212
protected static class TestConfig {
187213

0 commit comments

Comments
 (0)