diff options
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"); } } |