From 9f5a860d1ecaebb80530fc22607d34fc80d8c09d Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Thu, 04 Oct 2012 08:04:49 -0400 Subject: [PATCH] Fixed duplicate entries in repository cache (issue 140) --- src/com/gitblit/utils/StringUtils.java | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-) diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java index e440790..0711338 100644 --- a/src/com/gitblit/utils/StringUtils.java +++ b/src/com/gitblit/utils/StringUtils.java @@ -367,7 +367,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 +660,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; + } } \ No newline at end of file -- Gitblit v1.9.1