From 63fa2ef7c4211828834ef69423966676f0843d7b Mon Sep 17 00:00:00 2001 From: David Kocher Date: Wed, 20 Dec 2006 21:07:01 +0000 Subject: [PATCH] Adding option not to normalize paths, see #972 --- source/ch/cyberduck/core/Path.java | 74 +++++++++++++++--------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/source/ch/cyberduck/core/Path.java b/source/ch/cyberduck/core/Path.java index 278f7b6897d..3c4029b28e7 100644 --- a/source/ch/cyberduck/core/Path.java +++ b/source/ch/cyberduck/core/Path.java @@ -224,46 +224,48 @@ public Path getParent() { */ public static String normalize(final String path) { String normalized = path; - while(!normalized.startsWith(DELIMITER)) { - normalized = DELIMITER + normalized; - } - while(!normalized.endsWith(DELIMITER)) { - normalized = normalized + DELIMITER; - } - // Resolve occurrences of "/./" in the normalized path - while(true) { - int index = normalized.indexOf("/./"); - if(index < 0) { - break; + if(Preferences.instance().getBoolean("path.normalize")) { + while(!normalized.startsWith(DELIMITER)) { + normalized = DELIMITER + normalized; } - normalized = normalized.substring(0, index) + - normalized.substring(index + 2); - } - // Resolve occurrences of "/../" in the normalized path - while(true) { - int index = normalized.indexOf("/../"); - if(index < 0) { - break; + while(!normalized.endsWith(DELIMITER)) { + normalized = normalized + DELIMITER; } - if (index == 0) { - return DELIMITER; // The only left path is the root. + // Resolve occurrences of "/./" in the normalized path + while(true) { + int index = normalized.indexOf("/./"); + if(index < 0) { + break; + } + normalized = normalized.substring(0, index) + + normalized.substring(index + 2); } - normalized = normalized.substring(0, normalized.lastIndexOf('/', index - 1)) + - normalized.substring(index + 3); - } - // Resolve occurrences of "//" in the normalized path - while(true) { - int index = normalized.indexOf("//"); - if(index < 0) { - break; + // Resolve occurrences of "/../" in the normalized path + while(true) { + int index = normalized.indexOf("/../"); + if(index < 0) { + break; + } + if (index == 0) { + return DELIMITER; // The only left path is the root. + } + normalized = normalized.substring(0, normalized.lastIndexOf('/', index - 1)) + + normalized.substring(index + 3); + } + // Resolve occurrences of "//" in the normalized path + while(true) { + int index = normalized.indexOf("//"); + if(index < 0) { + break; + } + normalized = normalized.substring(0, index) + + normalized.substring(index + 1); + } + while((normalized.endsWith(DELIMITER) && (normalized.length() + > 1))) { + //Strip any redundant delimiter at the end of the path + normalized = normalized.substring(0, normalized.length() - 1); } - normalized = normalized.substring(0, index) + - normalized.substring(index + 1); - } - while((normalized.endsWith(DELIMITER) && (normalized.length() - > 1))) { - //Strip any redundant delimiter at the end of the path - normalized = normalized.substring(0, normalized.length() - 1); } // Return the normalized path that we have completed return normalized;