diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-09-18 11:33:18 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-09-19 08:56:33 +0200 |
commit | af30430e1577d2284a1fce12f8a8a43652627461 (patch) | |
tree | f283f08696b9ee015ccdad0c04d66f116774e6b8 /sonar-batch | |
parent | 8b80e32f4e020ecc82b6e4fd6fd01b5d9374167a (diff) | |
download | sonarqube-af30430e1577d2284a1fce12f8a8a43652627461.tar.gz sonarqube-af30430e1577d2284a1fce12f8a8a43652627461.zip |
SONAR-6834 complete filtering paramters of api/ce/activity
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java | 6 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/util/BatchUtilsTest.java | 35 |
2 files changed, 39 insertions, 2 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java b/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java index b5460a6e2a1..3051ba40067 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java +++ b/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java @@ -19,9 +19,11 @@ */ package org.sonar.batch.util; +import com.google.common.base.Strings; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; public class BatchUtils { @@ -38,9 +40,9 @@ public class BatchUtils { return StringUtils.replace(cleanKey, ":", "_"); } - public static String encodeForUrl(String url) { + public static String encodeForUrl(@Nullable String url) { try { - return URLEncoder.encode(url, "UTF-8"); + return URLEncoder.encode(Strings.nullToEmpty(url), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Encoding not supported", e); diff --git a/sonar-batch/src/test/java/org/sonar/batch/util/BatchUtilsTest.java b/sonar-batch/src/test/java/org/sonar/batch/util/BatchUtilsTest.java new file mode 100644 index 00000000000..7926172f078 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/util/BatchUtilsTest.java @@ -0,0 +1,35 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.batch.util; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class BatchUtilsTest { + + @Test + public void encodeForUrl() throws Exception { + assertThat(BatchUtils.encodeForUrl(null)).isEqualTo(""); + assertThat(BatchUtils.encodeForUrl("")).isEqualTo(""); + assertThat(BatchUtils.encodeForUrl("foo")).isEqualTo("foo"); + assertThat(BatchUtils.encodeForUrl("foo&bar")).isEqualTo("foo%26bar"); + } +} |