ugo 2004/05/01 10:04:10
Modified: src/java/org/apache/cocoon/util NetUtils.java
Log:
Make NetUtils.normalize() compliant with the latest testcases.
Revision Changes Path
1.15 +11 -4 cocoon-2.1/src/java/org/apache/cocoon/util/NetUtils.java
Index: NetUtils.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/util/NetUtils.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- NetUtils.java 29 Apr 2004 20:10:04 -0000 1.14
+++ NetUtils.java 1 May 2004 17:04:10 -0000 1.15
@@ -325,22 +325,29 @@
if ("".equals(uri)) {
return uri;
}
- boolean isAbs = (uri.charAt(0) == '/');
+ int leadingSlashes = 0;
+ for (leadingSlashes = 0 ; leadingSlashes < uri.length()
+ && uri.charAt(leadingSlashes) == '/' ; ++leadingSlashes) {}
boolean isDir = (uri.charAt(uri.length() - 1) == '/');
StringTokenizer st = new StringTokenizer(uri, "/");
LinkedList clean = new LinkedList();
while (st.hasMoreTokens()) {
String token = st.nextToken();
if ("..".equals(token)) {
- if (! clean.isEmpty()) {
+ if (! clean.isEmpty() && ! "..".equals(clean.getLast())) {
clean.removeLast();
+ if (! st.hasMoreTokens()) {
+ isDir = true;
+ }
+ } else {
+ clean.add("..");
}
} else if (! ".".equals(token) && ! "".equals(token)) {
clean.add(token);
}
}
StringBuffer sb = new StringBuffer();
- if (isAbs) {
+ while (leadingSlashes-- > 0) {
sb.append('/');
}
for (Iterator it = clean.iterator() ; it.hasNext() ; ) {