]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5915 Escape project key when loading project referentials
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 9 Dec 2014 13:36:33 +0000 (14:36 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 9 Dec 2014 13:37:08 +0000 (14:37 +0100)
sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java

index f448d257f608ce83af143f6c1518820ccc01b770..bf2957084ce31db8f4819a0c378a2e1c078f7652 100644 (file)
@@ -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.");
index d715ae4f34bf35230f74389a5a7072b05bfd029e..9da2dbf5cb7a14caf42643055e402c8b51aeabef 100644 (file)
@@ -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");
   }
 
 }