From: Juergen H. <jho...@us...> - 2008-10-22 10:33:51
|
Update of /cvsroot/springframework/spring/src/org/springframework/util In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv25875/src/org/springframework/util Modified Files: Tag: mbranch-2-0 StringUtils.java Log Message: fixed "StringUtils.delete" to prevent an eternal loop in case of the pattern being empty; "StringUtils.cleanPath" preserves leading slash if given in original path Index: StringUtils.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/util/StringUtils.java,v retrieving revision 1.59.2.5 retrieving revision 1.59.2.6 diff -C2 -d -r1.59.2.5 -r1.59.2.6 *** StringUtils.java 29 Feb 2008 22:40:50 -0000 1.59.2.5 --- StringUtils.java 22 Oct 2008 10:33:32 -0000 1.59.2.6 *************** *** 300,310 **** */ public static String replace(String inString, String oldPattern, String newPattern) { ! if (inString == null) { ! return null; ! } ! if (oldPattern == null || newPattern == null) { return inString; } - StringBuffer sbuf = new StringBuffer(); // output StringBuffer we'll build up --- 300,306 ---- */ public static String replace(String inString, String oldPattern, String newPattern) { ! if (!hasLength(inString) || !hasLength(oldPattern) || newPattern == null) { return inString; } StringBuffer sbuf = new StringBuffer(); // output StringBuffer we'll build up *************** *** 320,324 **** } sbuf.append(inString.substring(pos)); - // remember to append any characters to the right of a match return sbuf.toString(); --- 316,319 ---- *************** *** 512,515 **** --- 507,513 ---- */ public static String cleanPath(String path) { + if (path == null) { + return null; + } String pathToUse = replace(path, WINDOWS_FOLDER_SEPARATOR, FOLDER_SEPARATOR); *************** *** 524,527 **** --- 522,529 ---- pathToUse = pathToUse.substring(prefixIndex + 1); } + if (pathToUse.startsWith(FOLDER_SEPARATOR)) { + prefix = prefix + FOLDER_SEPARATOR; + pathToUse = pathToUse.substring(1); + } String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR); *************** *** 530,537 **** for (int i = pathArray.length - 1; i >= 0; i--) { ! if (CURRENT_PATH.equals(pathArray[i])) { // Points to current directory - drop it. } ! else if (TOP_PATH.equals(pathArray[i])) { // Registering top path found. tops++; --- 532,540 ---- for (int i = pathArray.length - 1; i >= 0; i--) { ! String element = pathArray[i]; ! if (CURRENT_PATH.equals(element)) { // Points to current directory - drop it. } ! else if (TOP_PATH.equals(element)) { // Registering top path found. tops++; *************** *** 539,548 **** else { if (tops > 0) { ! // Merging path element with corresponding to top path. tops--; } else { // Normal path element found. ! pathElements.add(0, pathArray[i]); } } --- 542,551 ---- else { if (tops > 0) { ! // Merging path element with element corresponding to top path. tops--; } else { // Normal path element found. ! pathElements.add(0, element); } } |