]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7969 Replace "%2C" by "," in multi values settings 1181/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 26 Aug 2016 11:50:50 +0000 (13:50 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 26 Aug 2016 12:46:49 +0000 (14:46 +0200)
server/sonar-server/src/main/java/org/sonar/server/settings/ws/ValuesAction.java
server/sonar-server/src/test/java/org/sonar/server/settings/ws/ValuesActionTest.java

index a82fe4db3e9df10455c98717c1aebf863e90aaba..e12b72add4c7776e2260ad2dbc090806d4034bc2 100644 (file)
@@ -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<String> 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);
       }
index 878af16405973f573c6696511bff1439c542d173..01eb10674ffcb7803bd48ed3bca1a56f068c2db6 100644 (file)
@@ -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();