]> source.dussan.org Git - gitblit.git/commitdiff
Fix possible string index out of bounds exception
authorJames Moger <james.moger@gitblit.com>
Wed, 10 Oct 2012 20:11:17 +0000 (16:11 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 10 Oct 2012 20:11:17 +0000 (16:11 -0400)
src/com/gitblit/utils/StringUtils.java

index 07113388a7e86f4f45225e97a7a5dbec516e9b6c..d115f896d717773347c9a9acd7a9d6bf0feae9dd 100644 (file)
@@ -315,11 +315,16 @@ public class StringUtils {
         * @return the relative path\r
         */\r
        public static String getRelativePath(String basePath, String fullPath) {\r
-               String relativePath = fullPath.substring(basePath.length()).replace('\\', '/');\r
-               if (relativePath.charAt(0) == '/') {\r
-                       relativePath = relativePath.substring(1);\r
+               String bp = basePath.replace('\\', '/').toLowerCase();\r
+               String fp = fullPath.replace('\\', '/').toLowerCase();\r
+               if (fp.startsWith(bp)) {\r
+                       String relativePath = fullPath.substring(basePath.length()).replace('\\', '/');\r
+                       if (relativePath.charAt(0) == '/') {\r
+                               relativePath = relativePath.substring(1);\r
+                       }\r
+                       return relativePath;\r
                }\r
-               return relativePath;\r
+               return fullPath;\r
        }\r
 \r
        /**\r