]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11561 Allow more special characters in branch names
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 1 Mar 2019 14:17:32 +0000 (08:17 -0600)
committersonartech <sonartech@sonarsource.com>
Wed, 6 Mar 2019 10:30:44 +0000 (11:30 +0100)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java
sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java

index 09c83904ac0a970a4ea81cde9955a70449fcee39..ae137aa4743b544757803a37be339f4d9357a0ba 100644 (file)
@@ -47,7 +47,7 @@ public class DefaultBranchImpl implements Branch {
   public DefaultBranchImpl(@Nullable String name) {
     this.isLegacyBranch = (name != null);
     this.branchName = (name == null) ? BranchDto.DEFAULT_MAIN_BRANCH_NAME : name;
-    if (!ComponentKeys.isValidBranch(branchName)) {
+    if (!ComponentKeys.isValidLegacyBranch(branchName)) {
       throw MessageException.of(format("\"%s\" is not a valid branch name. "
         + "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branchName));
     }
index 8c784b3ad2b9e267b13b1554070c783a5a85091a..0eb1efecd36d4f1ad590b449843a0de8a9843c86 100644 (file)
@@ -100,7 +100,7 @@ public class ComponentUpdater {
   }
 
   private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) {
-    checkBranchFormat(newComponent.qualifier(), newComponent.deprecatedBranch());
+    checkLegacyBranchFormat(newComponent.qualifier(), newComponent.deprecatedBranch());
     String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.deprecatedBranch());
     checkRequest(!dbClient.componentDao().selectByKey(session, keyWithBranch).isPresent(),
       "Could not create %s, key already exists: %s", getQualifierToDisplay(newComponent.qualifier()), keyWithBranch);
@@ -169,8 +169,8 @@ public class ComponentUpdater {
       "Malformed key for %s: %s. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", getQualifierToDisplay(qualifier), key);
   }
 
-  private void checkBranchFormat(String qualifier, @Nullable String branch) {
-    checkRequest(branch == null || ComponentKeys.isValidBranch(branch),
+  private void checkLegacyBranchFormat(String qualifier, @Nullable String branch) {
+    checkRequest(branch == null || ComponentKeys.isValidLegacyBranch(branch),
       "Malformed branch for %s: %s. Allowed characters are alphanumeric, '-', '_', '.' and '/', with at least one non-digit.", getQualifierToDisplay(qualifier), branch);
   }
 
index 93cbbe0439f0a68861fe46c9c00f38a7dec62fb0..a3bb4fb14533e9dd65d408cda1add490e040f0cd 100644 (file)
@@ -111,7 +111,7 @@ public final class ComponentKeys {
    *
    * @return <code>true</code> if <code>branchCandidate</code> can be used for a project
    */
-  public static boolean isValidBranch(String branchCandidate) {
+  public static boolean isValidLegacyBranch(String branchCandidate) {
     return branchCandidate.matches(VALID_BRANCH_REGEXP);
   }
 
index d4f45a6976900f60a41ad89dcd23d6e6326d9718..a328a0c586b8bb7ee697d9484c93ebe2d8c9da25 100644 (file)
@@ -68,14 +68,14 @@ public class ComponentKeysTest {
 
   @Test
   public void isValidBranchKey() {
-    assertThat(ComponentKeys.isValidBranch("")).isTrue();
-    assertThat(ComponentKeys.isValidBranch("abc")).isTrue();
-    assertThat(ComponentKeys.isValidBranch("0123")).isTrue();
-    assertThat(ComponentKeys.isValidBranch("ab 12")).isFalse();
-    assertThat(ComponentKeys.isValidBranch("ab_12")).isTrue();
-    assertThat(ComponentKeys.isValidBranch("ab/12")).isTrue();
-    assertThat(ComponentKeys.isValidBranch("ab\\12")).isFalse();
-    assertThat(ComponentKeys.isValidBranch("ab\n")).isFalse();
+    assertThat(ComponentKeys.isValidLegacyBranch("")).isTrue();
+    assertThat(ComponentKeys.isValidLegacyBranch("abc")).isTrue();
+    assertThat(ComponentKeys.isValidLegacyBranch("0123")).isTrue();
+    assertThat(ComponentKeys.isValidLegacyBranch("ab 12")).isFalse();
+    assertThat(ComponentKeys.isValidLegacyBranch("ab_12")).isTrue();
+    assertThat(ComponentKeys.isValidLegacyBranch("ab/12")).isTrue();
+    assertThat(ComponentKeys.isValidLegacyBranch("ab\\12")).isFalse();
+    assertThat(ComponentKeys.isValidLegacyBranch("ab\n")).isFalse();
   }
 
   @Test
index fb67d7dc0fa95f899400afb5f40be78d4a104742..c49d685c9c31918115b0b3e19d29c18d395bc728 100644 (file)
@@ -85,7 +85,7 @@ public class ProjectReactorValidator {
       validatePullRequestParamsWhenPluginAbsent(validationMessages);
     }
 
-    validateBranch(validationMessages, deprecatedBranchName);
+    validateLegacyBranch(validationMessages, deprecatedBranchName);
 
     if (!validationMessages.isEmpty()) {
       throw MessageException.of("Validation of project reactor failed:\n  o " + Joiner.on("\n  o ").join(validationMessages));
@@ -122,8 +122,8 @@ public class ProjectReactorValidator {
     }
   }
 
-  private static void validateBranch(List<String> validationMessages, @Nullable String branch) {
-    if (isNotEmpty(branch) && !ComponentKeys.isValidBranch(branch)) {
+  private static void validateLegacyBranch(List<String> validationMessages, @Nullable String branch) {
+    if (isNotEmpty(branch) && !ComponentKeys.isValidLegacyBranch(branch)) {
       validationMessages.add(format("\"%s\" is not a valid branch name. "
         + "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branch));
     }