Support nullable flag value in ShortcutConfigurable.ShortcutType#GATHER_LIST_TAIL_FLAG

Fixes gh-3049
This commit is contained in:
Muchnik Andrey
2023-09-12 00:33:22 +03:00
committed by sgibb
parent b3acabfecf
commit 82639855b6
2 changed files with 27 additions and 1 deletions

View File

@@ -151,7 +151,7 @@ public interface ShortcutConfigurable {
// strip boolean flag if last entry is true or false
int lastIdx = values.size() - 1;
String lastValue = values.get(lastIdx);
if (lastValue.equalsIgnoreCase("true") || lastValue.equalsIgnoreCase("false")) {
if ("true".equalsIgnoreCase(lastValue) || "false".equalsIgnoreCase(lastValue) || lastValue == null) {
values = values.subList(0, lastIdx);
map.put(fieldOrder.get(1), getValue(parser, beanFactory, lastValue));
}

View File

@@ -182,6 +182,32 @@ public class ShortcutConfigurableTests {
}
}
@Test
public void testNormalizeGatherListTailFlagFlagIsNull() {
parser = new SpelExpressionParser();
ShortcutConfigurable shortcutConfigurable = new ShortcutConfigurable() {
@Override
public List<String> shortcutFieldOrder() {
return Arrays.asList("values", "flag");
}
@Override
public ShortcutType shortcutType() {
return ShortcutType.GATHER_LIST_TAIL_FLAG;
}
};
Map<String, String> args = new HashMap<>();
args.put("1", "val0");
args.put("2", "val1");
args.put("3", "val2");
args.put("4", null);
Map<String, Object> map = ShortcutType.GATHER_LIST_TAIL_FLAG.normalize(args, shortcutConfigurable, parser,
this.beanFactory);
assertThat(map).isNotNull().containsKey("values");
assertThat((List) map.get("values")).containsExactly("val0", "val1", "val2");
assertThat(map.get("flag")).isNull();
}
@SpringBootConfiguration
protected static class TestConfig {