[jboss-cvs] JBossAS SVN: r80665 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 7 10:51:57 EST 2008


Author: alesj
Date: 2008-11-07 10:51:57 -0500 (Fri, 07 Nov 2008)
New Revision: 80665

Modified:
   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/PathTokensTestCase.java
Log:
[JBVFS-72]; allow any path token.

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-11-07 15:19:32 UTC (rev 80664)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/helpers/PathTokenizer.java	2008-11-07 15:51:57 UTC (rev 80665)
@@ -41,6 +41,9 @@
    /** The reverse path const */
    private static final String REVERSE_PATH = "..";
 
+   /** Catch some suspicious tokens */
+   private static boolean errorOnSuspiciousTokens;
+
    /**
     * Utility class
     */
@@ -124,7 +127,13 @@
             else if (specialToken == CURRENT_PATH && bufferLength == 0)
                specialToken = REVERSE_PATH;
             else if (specialToken == REVERSE_PATH && bufferLength == 0)
-               throw new IllegalArgumentException("Illegal token (" + specialToken + ch + ") in path: " + path);
+            {
+               if (errorOnSuspiciousTokens)
+                  throw new IllegalArgumentException("Illegal token (" + specialToken + ch + ") in path: " + path);
+
+               buffer.append(specialToken).append(ch);
+               specialToken = null;
+            }
             else
                buffer.append(ch);
          }
@@ -134,7 +143,7 @@
             if (specialToken != null)
             {
                // we don't allow tokens after '..'
-               if (specialToken == REVERSE_PATH)
+               if (errorOnSuspiciousTokens && specialToken == REVERSE_PATH)
                   throw new IllegalArgumentException("Illegal token (" + specialToken + ch + ") in path: " + path);
 
                // after '.' more path is legal == unix hidden directories
@@ -222,4 +231,14 @@
    {
       return REVERSE_PATH == token;
    }
+
+   /**
+    * Set errorOnSuspiciousTokens flag.
+    *
+    * @param errorOnSuspiciousTokens the errorOnSuspiciousTokens flag
+    */
+   public static void setErrorOnSuspiciousTokens(boolean errorOnSuspiciousTokens)
+   {
+      PathTokenizer.errorOnSuspiciousTokens = errorOnSuspiciousTokens;
+   }
 }

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java	2008-11-07 15:19:32 UTC (rev 80664)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/PathTokensTestCase.java	2008-11-07 15:51:57 UTC (rev 80665)
@@ -80,15 +80,23 @@
 
    public void testSpecialTokens() throws Throwable
    {
-      testBrokenPath("/.../");
-      testBrokenPath(".../");
-      testBrokenPath("/...");
-      testBrokenPath("...");
-      testBrokenPath("/..somemorepath/");
-      testBrokenPath("..somemorepath/");
-      testBrokenPath("/..somemorepath");
-      testBrokenPath("..somemorepath");
+      PathTokenizer.setErrorOnSuspiciousTokens(true);
+      try
+      {
+         testBrokenPath("/.../");
+         testBrokenPath(".../");
+         testBrokenPath("/...");
+         testBrokenPath("...");
+         testBrokenPath("/..somemorepath/");
+         testBrokenPath("..somemorepath/");
+         testBrokenPath("/..somemorepath");
+         testBrokenPath("..somemorepath");
       }
+      finally
+      {
+         PathTokenizer.setErrorOnSuspiciousTokens(false);
+      }
+   }
 
    public void testRepeatedSlashes() throws Throwable
    {
@@ -107,12 +115,32 @@
       testValidPath("//context///jar///");
    }
 
-   public void testHiddenUnixPath() throws Throwable
+   public void testSuspiciousTokens() throws Throwable
    {
-      // the trick is the .hudson bit
-      String path = "/home/hudson/.hudson/";
-      List<String> tokens = PathTokenizer.getTokens(path);
-      List<String> expected = Arrays.asList("home", "hudson", ".hudson");
-      assertEquals(expected, tokens);
+      testSuspiciousTokens(false);
+      testSuspiciousTokens(true);      
    }
+
+   public void testSuspiciousTokens(boolean flag) throws Throwable
+   {
+      PathTokenizer.setErrorOnSuspiciousTokens(flag);
+      try
+      {
+         String path = "/.hudson/..hudson/...hudson/./../.../.*foo/foo.bar";
+         List<String> tokens = PathTokenizer.getTokens(path);
+         List<String> expected = Arrays.asList(".hudson", "..hudson", "...hudson", ".", "..", "...", ".*foo", "foo.bar");
+         assertEquals(expected, tokens);
+         if (flag)
+            fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         if (!flag)
+            throw t;
+      }
+      finally
+      {
+         PathTokenizer.setErrorOnSuspiciousTokens(!flag);
+      }
+   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list