aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-08-28 17:54:47 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-08-28 17:54:47 +0200
commitd466e731496434f5253d36f5c5b3599f4589fdaa (patch)
tree6adc7d62ab45621a966838c67199b87dcdb2bade /sonar-plugin-api
parentd9c700ff5c0c9e9908602c51aa24df492e76aa63 (diff)
downloadsonarqube-d466e731496434f5253d36f5c5b3599f4589fdaa.tar.gz
sonarqube-d466e731496434f5253d36f5c5b3599f4589fdaa.zip
Trim all WS string request parameters
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java22
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java1
2 files changed, 12 insertions, 11 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java
index 4e193931bf8..0c5efdcf525 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java
@@ -19,20 +19,19 @@
*/
package org.sonar.api.server.ws.internal;
+import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.log.Loggers;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.log.Loggers;
/**
* @since 4.2
@@ -65,10 +64,11 @@ public abstract class ValidatingRequest extends Request {
private String param(String key, boolean validateValue) {
WebService.Param definition = action.param(key);
String value = readParamOrDefaultValue(key, definition);
- if (value != null && validateValue) {
- validate(value, definition);
+ String trimmedValue = value == null ? value : CharMatcher.WHITESPACE.trimFrom(value);
+ if (trimmedValue != null && validateValue) {
+ validate(trimmedValue, definition);
}
- return value;
+ return trimmedValue;
}
@CheckForNull
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
index 5cae0e2cdda..a9cde1cc415 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/RequestTest.java
@@ -175,6 +175,7 @@ public class RequestTest {
@Test
public void param_as_string() {
assertThat(request.setParam("a_string", "foo").param("a_string")).isEqualTo("foo");
+ assertThat(request.setParam("a_string", " f o o \r\n ").param("a_string")).isEqualTo("f o o");
}
@Test