Skip to content

Commit

Permalink
Adding option not to normalize paths, see #972
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Dec 20, 2006
1 parent 32d927f commit 63fa2ef
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions source/ch/cyberduck/core/Path.java
Expand Up @@ -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;
Expand Down

0 comments on commit 63fa2ef

Please sign in to comment.