diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-12-09 14:36:33 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-12-09 14:37:08 +0100 |
commit | 1a48cf905ef021016f5df4d70a2838348911e6ee (patch) | |
tree | 811be17a190b61a2a3bab5182ca6e68b4af7b327 | |
parent | 3510b8f7bfc1f357e39827b4b853f185f407f0ab (diff) | |
download | sonarqube-1a48cf905ef021016f5df4d70a2838348911e6ee.tar.gz sonarqube-1a48cf905ef021016f5df4d70a2838348911e6ee.zip |
SONAR-5915 Escape project key when loading project referentials
2 files changed, 13 insertions, 5 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java index f448d257f60..bf2957084ce 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java @@ -74,7 +74,7 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad @Override public ProjectReferentials load(ProjectReactor reactor, TaskProperties taskProperties) { String projectKey = reactor.getRoot().getKeyWithBranch(); - String url = BATCH_PROJECT_URL + "?key=" + projectKey; + String url = BATCH_PROJECT_URL + "?key=" + ServerClient.encodeForUrl(projectKey); if (taskProperties.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) { LOG.warn("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server."); diff --git a/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java index d715ae4f34b..9da2dbf5cb7 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java @@ -54,12 +54,12 @@ public class DefaultProjectReferentialsLoaderTest { loader = spy(loader); doReturn(null).when(loader).lastSnapshotCreationDate(anyString()); when(serverClient.request(anyString())).thenReturn("{}"); - reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo")); taskProperties = new TaskProperties(Maps.<String, String>newHashMap(), ""); } @Test public void passPreviewParameter() { + reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo")); when(analysisMode.isPreview()).thenReturn(false); loader.load(reactor, taskProperties); verify(serverClient).request("/batch/project?key=foo&preview=false"); @@ -70,10 +70,18 @@ public class DefaultProjectReferentialsLoaderTest { } @Test - public void passProfileParameter() { - taskProperties.properties().put(ModuleQProfiles.SONAR_PROFILE_PROP, "my-profile"); + public void passAndEncodeProjectKeyParameter() { + reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo bàr")); + loader.load(reactor, taskProperties); + verify(serverClient).request("/batch/project?key=foo+b%C3%A0r&preview=false"); + } + + @Test + public void passAndEncodeProfileParameter() { + reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo")); + taskProperties.properties().put(ModuleQProfiles.SONAR_PROFILE_PROP, "my-profile#2"); loader.load(reactor, taskProperties); - verify(serverClient).request("/batch/project?key=foo&profile=my-profile&preview=false"); + verify(serverClient).request("/batch/project?key=foo&profile=my-profile%232&preview=false"); } } |