James Moger
2012-10-18 13417cf9c6eec555b51da49742e47939d2f5715b
src/com/gitblit/utils/StringUtils.java
@@ -315,11 +315,16 @@
    * @return the relative path
    */
   public static String getRelativePath(String basePath, String fullPath) {
      String relativePath = fullPath.substring(basePath.length()).replace('\\', '/');
      if (relativePath.charAt(0) == '/') {
         relativePath = relativePath.substring(1);
      String bp = basePath.replace('\\', '/').toLowerCase();
      String fp = fullPath.replace('\\', '/').toLowerCase();
      if (fp.startsWith(bp)) {
         String relativePath = fullPath.substring(basePath.length()).replace('\\', '/');
         if (relativePath.charAt(0) == '/') {
            relativePath = relativePath.substring(1);
         }
         return relativePath;
      }
      return relativePath;
      return fullPath;
   }
   /**
@@ -367,7 +372,7 @@
    * @return the first invalid character found or null if string is acceptable
    */
   public static Character findInvalidCharacter(String name) {
      char[] validChars = { '/', '.', '_', '-' };
      char[] validChars = { '/', '.', '_', '-', '~' };
      for (char c : name.toCharArray()) {
         if (!Character.isLetterOrDigit(c)) {
            boolean ok = false;
@@ -660,4 +665,31 @@
      }
      return input;
   }
   /**
    * Returns the first path element of a path string.  If no path separator is
    * found in the path, an empty string is returned.
    *
    * @param path
    * @return the first element in the path
    */
   public static String getFirstPathElement(String path) {
      if (path.indexOf('/') > -1) {
         return path.substring(0, path.indexOf('/')).trim();
      }
      return "";
   }
   /**
    * Returns the last path element of a path string
    *
    * @param path
    * @return the last element in the path
    */
   public static String getLastPathElement(String path) {
      if (path.indexOf('/') > -1) {
         return path.substring(path.lastIndexOf('/') + 1);
      }
      return path;
   }
}