--- WARDirContext.old 2002-07-13 06:04:37.000000000 -0400 +++ WARDirContext.java 2002-07-13 06:30:59.000000000 -0400 @@ -246,6 +246,7 @@ throws NamingException { if (name.isEmpty()) return this; + name = handleRelativePaths(name); //removes Dot and DotDot notation Entry entry = treeLookup(name); if (entry == null) throw new NamingException @@ -772,6 +773,35 @@ } + /** + * Handle Relative file path markers such as .. and . + * Assumes that the name will begin "/" and will maintain this + */ + protected static Name handleRelativePaths(Name BaseName) + throws NamingException { + boolean hasChanged = true; + Name name = BaseName.getSuffix(0); //creating a new name, so as not to modify the old + while(hasChanged) { + hasChanged = false; + for(int i = 0; i < name.size(); i++) { + //remove any Dot Dot notation, if it's not the root + if( name.get(i).equals("..") && i > 1) { //will not handle the case "/.." . let current system handle situation + name.remove(i); + name.remove(i - 1); + hasChanged = true; + break; //start over + } + + //removes any Single Dot notation + if( name.get(i).equals(".") ) { + name.remove(i); + hasChanged = true; + break; //start over + } + } + } + return name; + } /** * Constructs a tree of the entries contained in a WAR file.