Commits

Sebastian Sdorra committed e831925 Merge

merge with bracnh issue-470

Comments (0)

Files changed (3)

scm-core/src/main/java/sonia/scm/util/ValidationUtil.java

     "^[A-z0-9][\\w.-]*@[A-z0-9][\\w\\-\\.]+\\.[A-z0-9]{2,6}$";
 
   /** Field description */
-  private static final String REGEX_NAME = "^[A-z0-9\\.\\-_]+$";
+  private static final String REGEX_NAME =
+    "^[A-z0-9\\.\\-_@]|[^ ]([A-z0-9\\.\\-_@ ]*[A-z0-9\\.\\-_@]|[^ ])?$";
 
   /** Field description */
   private static final String REGEX_REPOSITORYNAME =
     "(?!^\\.\\.$)(?!^\\.$)(?!.*[\\\\\\[\\]])^[A-z0-9\\.][A-z0-9\\.\\-_/]*$";
 
-  /** Field description */
-  private static final String REGEX_USERNAME =
-    "^[A-z0-9\\.\\-_@]|[^ ]([A-z0-9\\.\\-_@ ]*[A-z0-9\\.\\-_@]|[^ ])?$";
-
   //~--- constructors ---------------------------------------------------------
 
   /**
    * @param username
    *
    * @return
+   * @deprecated use {@link #isNameValid(String)}
    */
+  @Deprecated
   public static boolean isUsernameValid(String username)
   {
-    return Util.isNotEmpty(username) && username.matches(REGEX_USERNAME);
+    return isNameValid(username);
   }
 
   /**

scm-core/src/test/java/sonia/scm/util/ValidationUtilTest.java

     assertTrue(ValidationUtil.isNameValid("test.git"));
     assertTrue(ValidationUtil.isNameValid("Test123.git"));
     assertTrue(ValidationUtil.isNameValid("Test123-git"));
-    assertTrue(ValidationUtil.isNameValid("Test_repository-123.git"));
+    assertTrue(ValidationUtil.isNameValid("Test_user-123.git"));
+    assertTrue(ValidationUtil.isNameValid("test@scm-manager.de"));
+    assertTrue(ValidationUtil.isNameValid("test 123"));
+    assertTrue(ValidationUtil.isNameValid("t"));
 
     // false
-    assertFalse(ValidationUtil.isNameValid("test 123"));
-    assertFalse(ValidationUtil.isNameValid("test@123"));
+    assertFalse(ValidationUtil.isNameValid(" test 123"));
+    assertFalse(ValidationUtil.isNameValid(" test 123 "));
+    assertFalse(ValidationUtil.isNameValid("test 123 "));
     assertFalse(ValidationUtil.isNameValid("test/123"));
     assertFalse(ValidationUtil.isNameValid("test%123"));
     assertFalse(ValidationUtil.isNameValid("test:123"));
+    assertFalse(ValidationUtil.isNameValid("t "));
+    assertFalse(ValidationUtil.isNameValid(" t"));
+    assertFalse(ValidationUtil.isNameValid(" t "));
   }
 
   /**
       assertFalse(ValidationUtil.isRepositoryNameValid(path));
     }
   }
-
-  /**
-   * Method description
-   *
-   */
-  @Test
-  public void testIsUsernameValid()
-  {
-
-    // true
-    assertTrue(ValidationUtil.isUsernameValid("test"));
-    assertTrue(ValidationUtil.isUsernameValid("test.git"));
-    assertTrue(ValidationUtil.isUsernameValid("Test123.git"));
-    assertTrue(ValidationUtil.isUsernameValid("Test123-git"));
-    assertTrue(ValidationUtil.isUsernameValid("Test_user-123.git"));
-    assertTrue(ValidationUtil.isUsernameValid("test@scm-manager.de"));
-    assertTrue(ValidationUtil.isUsernameValid("test 123"));
-    assertTrue(ValidationUtil.isUsernameValid("t"));
-
-    // false
-    assertFalse(ValidationUtil.isUsernameValid(" test 123"));
-    assertFalse(ValidationUtil.isUsernameValid(" test 123 "));
-    assertFalse(ValidationUtil.isUsernameValid("test 123 "));
-    assertFalse(ValidationUtil.isUsernameValid("test/123"));
-    assertFalse(ValidationUtil.isUsernameValid("test%123"));
-    assertFalse(ValidationUtil.isUsernameValid("test:123"));
-    assertFalse(ValidationUtil.isUsernameValid("t "));
-    assertFalse(ValidationUtil.isUsernameValid(" t"));
-    assertFalse(ValidationUtil.isUsernameValid(" t "));
-  }
 }

scm-webapp/src/main/webapp/resources/js/override/ext.form.vtypes.js

   // name validator
   
   name: function(val){
-    return /^[A-z0-9\.\-_]+$/.test(val);
+    return val.match(/^[^ ][A-z0-9\.\-_@ ]*[^ ]$/);
   },
   
   nameText: 'The name is invalid.',
   // username validator
   
   username: function(val){
-    return val.match(/^[^ ][A-z0-9\.\-_@ ]*[^ ]$/);
+    return name(val);
   },
   
   usernameText: 'The username is invalid.'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.