You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/03/02 20:48:42 UTC

svn commit: r1296413 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/ftp/FTPClient.java

Author: sebb
Date: Fri Mar  2 19:48:42 2012
New Revision: 1296413

URL: http://svn.apache.org/viewvc?rev=1296413&view=rev
Log:
NET-442 StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1296413&r1=1296412&r2=1296413&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Fri Mar  2 19:48:42 2012
@@ -65,6 +65,9 @@ The <action> type attribute can be add,u
         <release version="3.2" date="TBA" description="
         ">
 TBA
+            <action issue="NET-442" dev="sebb" type="fix">
+            StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory.
+            </action>
             <action issue="NET-444" dev="sebb" type="fix">
             FTPTimestampParserImpl fails to parse future dates correctly on Feb 28th in a leap year.
             </action>

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=1296413&r1=1296412&r2=1296413&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java Fri Mar  2 19:48:42 2012
@@ -469,15 +469,32 @@ implements Configurable
         __featuresMap = null;
     }
 
-    private String __parsePathname(String reply)
+    /**
+     * Parse the pathname from a CWD reply.
+     * According to RFC959 (http://www.ietf.org/rfc/rfc959.txt), 
+     * it should be the same as for MKD, i.e.
+     * 257<space>"<directory-name>"<space><commentary>
+     * where any embedded double-quotes are doubled.
+     * 
+     * However, see NET-442 for an exception.
+     * 
+     * @param reply
+     * @return
+     */
+    private static String __parsePathname(String reply)
     {
-        int begin = reply.indexOf('"') + 1;
-        int end = reply.indexOf('"', begin);
-
-        return reply.substring(begin, end);
+        int begin = reply.indexOf('"'); // find first double quote
+        if (begin == -1) { // not found, return all after reply code and space
+            return reply.substring(REPLY_CODE_LEN + 1);
+        }
+        int end = reply.lastIndexOf("\" "); // N.B. assume commentary does not contain double-quote
+        if (end != -1 ){ // found end of quoted string, de-duplicate any embedded quotes
+            return reply.substring(begin+1, end).replace("\"\"", "\"");            
+        }
+        // malformed reply, return all after reply code and space
+        return reply.substring(REPLY_CODE_LEN + 1);
     }
 
-
     protected void _parsePassiveModeReply(String reply)
     throws MalformedServerReplyException
     {