camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1226388 - in /camel/branches/camel-2.8.x: ./ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/util/ camel-core/src/test/java/org/apache/camel/util/ components/camel-ftp/src/main/java/org/a...
Date Mon, 02 Jan 2012 10:51:08 GMT
Author: davsclaus
Date: Mon Jan  2 10:51:07 2012
New Revision: 1226388

URL: http://svn.apache.org/viewvc?rev=1226388&view=rev
Log:
CAMEL-4850: Fixed NPE in ftp consumer if using empty starting directory with just two slashes.

Added:
    camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpTwoSlashesIssueTest.java
      - copied unchanged from r1226387, camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpTwoSlashesIssueTest.java
Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
    camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
    camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
    camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jan  2 10:51:07 2012
@@ -1 +1 @@
-/camel/trunk:1212504,1215477,1221565,1224674,1225077-1225078,1225766,1226081
+/camel/trunk:1212504,1215477,1221565,1224674,1225077-1225078,1225766,1226081,1226387

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=1226388&r1=1226387&r2=1226388&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
(original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
Mon Jan  2 10:51:07 2012
@@ -274,7 +274,12 @@ public class GenericFile<T>  {
             parent = path.getParent();
         } else {
             String name = getRelativeFilePath();
-            File path = new File(endpointPath, name);
+            File path;
+            if (name != null) {
+                path = new File(endpointPath, name);
+            } else {
+                path = new File(endpointPath);
+            }
             parent = path.getParent();
         }
         return normalizePathToProtocol(parent);

Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java?rev=1226388&r1=1226387&r2=1226388&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
(original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
Mon Jan  2 10:51:07 2012
@@ -130,13 +130,25 @@ public final class FileUtil {
      * Strip any trailing separators
      */
     public static String stripTrailingSeparator(String name) {
-        if (name == null) {
-            return null;
+        if (ObjectHelper.isEmpty(name)) {
+            return name;
         }
-        while (name.endsWith("/") || name.endsWith(File.separator)) {
-            name = name.substring(0, name.length() - 1);
+        
+        String s = name;
+        
+        // there must be some leading text, as we should only remove trailing separators

+        while (s.endsWith("/") || s.endsWith(File.separator)) {
+            s = s.substring(0, s.length() - 1);
+        }
+        
+        // if the string is empty, that means there was only trailing slashes, and no leading
text
+        // and so we should then return the original name as is
+        if (ObjectHelper.isEmpty(s)) {
+            return name;
+        } else {
+            // return without trailing slashes
+            return s;
         }
-        return name;
     }
 
     /**

Modified: camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java?rev=1226388&r1=1226387&r2=1226388&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
(original)
+++ camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
Mon Jan  2 10:51:07 2012
@@ -75,6 +75,11 @@ public class FileUtilTest extends TestCa
         assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar/"));
         assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar//"));
         assertEquals("/foo/bar", FileUtil.stripTrailingSeparator("/foo/bar///"));
+
+        assertEquals("/foo", FileUtil.stripTrailingSeparator("/foo"));
+        assertEquals("/foo", FileUtil.stripTrailingSeparator("/foo/"));
+        assertEquals("/", FileUtil.stripTrailingSeparator("/"));
+        assertEquals("//", FileUtil.stripTrailingSeparator("//"));
     }
 
     public void testStripPath() {

Modified: camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java?rev=1226388&r1=1226387&r2=1226388&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
Mon Jan  2 10:51:07 2012
@@ -52,8 +52,8 @@ public class FtpComponent extends Remote
     }
 
     /**
-     * get the base uri part before the options as they can be non URI valid such as the
expression using $ chars
-     * and the URI constructor will regard $ as an illegal character and we dont want to
enforce end users to
+     * Get the base uri part before the options as they can be non URI valid such as the
expression using $ chars
+     * and the URI constructor will regard $ as an illegal character and we don't want to
enforce end users to
      * to escape the $ for the expression (file language)
      */
     protected String getBaseUri(String uri) {



Mime
View raw message