[jboss-cvs] JBossAS SVN: r69360 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/vfs/helpers and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 25 19:37:36 EST 2008
Author: alesj
Date: 2008-01-25 19:37:36 -0500 (Fri, 25 Jan 2008)
New Revision: 69360
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSContextTest.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java
Log:
Handle current path - '.'
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2008-01-26 00:33:49 UTC (rev 69359)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2008-01-26 00:37:36 UTC (rev 69360)
@@ -345,24 +345,27 @@
if (current == null || current.isLeaf())
return null;
- if (PathTokenizer.isReverseToken(tokens[i]))
+ if (PathTokenizer.isCurrentToken(tokens[i]) == false)
{
- VirtualFileHandler parent = current.getParent();
- if (parent == null) // TODO - still IOE or null?
- throw new IOException("Using reverse path on top file handler: " + current + ", " + path);
+ if (PathTokenizer.isReverseToken(tokens[i]))
+ {
+ VirtualFileHandler parent = current.getParent();
+ if (parent == null) // TODO - still IOE or null?
+ throw new IOException("Using reverse path on top file handler: " + current + ", " + path);
+ else
+ current = parent;
+ }
+ else if (current instanceof StructuredVirtualFileHandler)
+ {
+ StructuredVirtualFileHandler structured = (StructuredVirtualFileHandler) current;
+ current = structured.createChildHandler(tokens[i]);
+ }
else
- current = parent;
+ {
+ String remainingPath = PathTokenizer.getRemainingPath(tokens, i);
+ return current.getChild(remainingPath);
+ }
}
- else if (current instanceof StructuredVirtualFileHandler)
- {
- StructuredVirtualFileHandler structured = (StructuredVirtualFileHandler) current;
- current = structured.createChildHandler(tokens[i]);
- }
- else
- {
- String remainingPath = PathTokenizer.getRemainingPath(tokens, i);
- return current.getChild(remainingPath);
- }
}
// The last one is the result
@@ -386,7 +389,7 @@
return this;
// check for reverse .. path
- String appliedPath = PathTokenizer.applyReversePaths(path);
+ String appliedPath = PathTokenizer.applySpecialPaths(path);
List<VirtualFileHandler> children = getChildren(false);
for (VirtualFileHandler child : children)
{
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java 2008-01-26 00:33:49 UTC (rev 69359)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java 2008-01-26 00:37:36 UTC (rev 69360)
@@ -34,6 +34,9 @@
public class PathTokenizer
{
/** The reverse path const */
+ private static final String CURRENT_PATH = ".";
+
+ /** The reverse path const */
private static final String REVERSE_PATH = "..";
/**
@@ -97,8 +100,6 @@
if ("".equals(token))
throw new IllegalArgumentException("A path element is empty: " + path);
- if (".".equals(token))
- throw new IllegalArgumentException("Single . in path is not allowed: " + path);
tokens[i++] = token;
}
@@ -122,13 +123,13 @@
}
/**
- * Apply any .. paths in the path param.
+ * Apply any . or .. paths in the path param.
*
* @param path the path
- * @return simple path, containing no .. paths
+ * @return simple path, containing no . or .. paths
* @throws IOException if reverse path goes over the top path
*/
- public static String applyReversePaths(String path) throws IOException
+ public static String applySpecialPaths(String path) throws IOException
{
String[] tokens = getTokens(path);
if (tokens == null)
@@ -137,10 +138,14 @@
int i = 0;
for(int j = 0; j < tokens.length; j++)
{
- if (isReverseToken(tokens[j]))
+ String token = tokens[j];
+
+ if (isCurrentToken(token))
+ continue;
+ else if (isReverseToken(token))
i--;
else
- tokens[i++] = tokens[j];
+ tokens[i++] = token;
if (i < 0)
throw new IOException("Using reverse path on top path: " + path);
@@ -149,10 +154,21 @@
}
/**
+ * Is current token.
+ *
+ * @param token the token to check
+ * @return true if token matches current path token
+ */
+ public static boolean isCurrentToken(String token)
+ {
+ return CURRENT_PATH.equals(token);
+ }
+
+ /**
* Is reverse token.
*
* @param token the token to check
- * @return true if token matches reverse path token
+ * @return true if token matches reverse path token
*/
public static boolean isReverseToken(String token)
{
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSContextTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSContextTest.java 2008-01-26 00:33:49 UTC (rev 69359)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractVFSContextTest.java 2008-01-26 00:37:36 UTC (rev 69360)
@@ -200,12 +200,12 @@
public void testSimpleReversePath() throws Exception
{
- checkReversePath("simple" + getSuffix() + "/../complex" + getSuffix() + "/subfolder/subsubfolder/../subchild", "subchild");
+ checkSpecialPath("simple" + getSuffix() + "/../complex" + getSuffix() + "/subfolder/subsubfolder/../subchild", "subchild");
}
public void testComplexReversePath() throws Exception
{
- checkReversePath("complex" + getSuffix() + "/../simple" + getSuffix() + "/child", "child");
+ checkSpecialPath("complex" + getSuffix() + "/../simple" + getSuffix() + "/child", "child");
}
public void testDirectOverTheTop() throws Exception
@@ -222,7 +222,7 @@
{
try
{
- checkReversePath(path, null);
+ checkSpecialPath(path, null);
fail("Should not be here.");
}
catch(Exception e)
@@ -231,8 +231,26 @@
}
}
- protected void checkReversePath(String path, String fileName) throws Exception
+ public void testCurrentAtTheStart() throws Exception
{
+ checkSpecialPath("./simple" + getSuffix() + "/child", "child");
+ checkSpecialPath("./complex" + getSuffix() + "/subfolder/subchild", "subchild");
+ }
+
+ public void testCurrentInTheMiddle() throws Exception
+ {
+ checkSpecialPath("simple" + getSuffix() + "/./child", "child");
+ checkSpecialPath("complex" + getSuffix() + "/./subfolder/subchild", "subchild");
+ }
+
+ public void testConcurrentCurrent() throws Exception
+ {
+ checkSpecialPath("././simple" + getSuffix() + "/././child", "child");
+ checkSpecialPath("././complex" + getSuffix() + "/././subfolder/subchild", "subchild");
+ }
+
+ protected void checkSpecialPath(String path, String fileName) throws Exception
+ {
VFSContext context = getParentVFSContext();
VirtualFileHandler root = context.getRoot();
VirtualFileHandler child = context.getChild(root, path);
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java 2008-01-26 00:33:49 UTC (rev 69359)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java 2008-01-26 00:37:36 UTC (rev 69360)
@@ -1235,6 +1235,9 @@
assertFindChild(root, "", root);
assertFindChild(root, "folder2/../folder1/child1", child1);
assertFindChild(root, "folder3/child1/../../folder2/child2", child2);
+ assertFindChild(root, "./folder1/child1", child1);
+ assertFindChild(root, "folder2/./child2", child2);
+ assertFindChild(root, "././folder2/././child2", child2);
try
{
assertFindChild(root, "../folder3/child3", child3);
More information about the jboss-cvs-commits
mailing list