From: Julien Lancelot Date: Fri, 26 Aug 2016 11:50:50 +0000 (+0200) Subject: SONAR-7969 Replace "%2C" by "," in multi values settings X-Git-Tag: 6.1-RC1~285 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1181%2Fhead;p=sonarqube.git SONAR-7969 Replace "%2C" by "," in multi values settings --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java b/server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java index a82fe4db3e9..e12b72add4c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java @@ -61,6 +61,7 @@ import static org.sonarqube.ws.client.setting.SettingsWsParameters.PARAM_KEYS; public class ValuesAction implements SettingsWsAction { private static final Splitter COMMA_SPLITTER = Splitter.on(","); + private static final String COMMA_ENCODED_VALUE = "%2C"; private final DbClient dbClient; private final ComponentFinder componentFinder; @@ -224,7 +225,8 @@ public class ValuesAction implements SettingsWsAction { } valueBuilder.setFieldsValues(builder); } else if (definition.multiValues()) { - valueBuilder.setValues(Settings.Values.newBuilder().addAllValues(COMMA_SPLITTER.split(value))); + List values = COMMA_SPLITTER.splitToList(value).stream().map(v -> v.replace(COMMA_ENCODED_VALUE, ",")).collect(Collectors.toList()); + valueBuilder.setValues(Settings.Values.newBuilder().addAllValues(values)); } else { valueBuilder.setValue(value); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/settings/ws/ValuesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/settings/ws/ValuesActionTest.java index 878af164059..01eb10674ff 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/settings/ws/ValuesActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/settings/ws/ValuesActionTest.java @@ -141,6 +141,20 @@ public class ValuesActionTest { assertThat(bar.hasFieldsValues()).isFalse(); } + @Test + public void return_multi_value_with_coma() throws Exception { + setUserAsSystemAdmin(); + propertyDefinitions.addComponent(PropertyDefinition.builder("global").multiValues(true).build()); + insertProperties(newGlobalPropertyDto().setKey("global").setValue("three,four%2Cfive")); + + ValuesWsResponse result = executeRequestForGlobalProperties("global"); + + assertThat(result.getSettingsList()).hasSize(1); + Settings.Setting setting = result.getSettings(0); + assertThat(setting.getKey()).isEqualTo("global"); + assertThat(setting.getValues().getValuesList()).containsOnly("three", "four,five"); + } + @Test public void return_property_set() throws Exception { setUserAsSystemAdmin();