Skip to content

Commit

Permalink
Tests and fix for #5573.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Dec 16, 2010
1 parent 8e0222c commit 4bfbe7a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
23 changes: 14 additions & 9 deletions source/ch/cyberduck/core/ftp/FTPPath.java
Expand Up @@ -375,7 +375,8 @@ protected boolean parseMlsdResponse(final AttributedList<Path> children, List<St
continue;
}
for(String name : file.keySet()) {
final Path parsed = PathFactory.createPath(this.getSession(), this.getAbsolute(), name, Path.FILE_TYPE);
final Path parsed = PathFactory.createPath(this.getSession(), this.getAbsolute(),
StringUtils.removeStart(name, this.getAbsolute() + Path.DELIMITER), Path.FILE_TYPE);
parsed.setParent(this);
// size -- Size in octets
// modify -- Last modification time
Expand All @@ -402,9 +403,11 @@ else if("file".equals(facts.get("type").toLowerCase())) {
break;
}
if(name.contains(String.valueOf(DELIMITER))) {
// The filename should never contain a delimiter according to RFC 3669
log.warn("Skip entry with delimiter:" + name);
break;
if(!name.startsWith(this.getAbsolute() + Path.DELIMITER)) {
// Workaround for #2434.
log.warn("Skip listing entry with delimiter:" + name);
continue;
}
}
if(!success) {
if("dir".equals(facts.get("type").toLowerCase()) && this.getName().equals(name)) {
Expand Down Expand Up @@ -486,18 +489,20 @@ protected boolean parseListResponse(final AttributedList<Path> children, FTPFile
if(this.getAbsolute().equals(name)) {
continue;
}
// Workaround for #2434.
if(name.contains(String.valueOf(DELIMITER))) {
// The filename should never contain a delimiter
log.warn("Skip listing entry with delimiter:" + name);
continue;
if(!name.startsWith(this.getAbsolute() + Path.DELIMITER)) {
// Workaround for #2434.
log.warn("Skip listing entry with delimiter:" + name);
continue;
}
}
}
success = true;
if(name.equals(".") || name.equals("..")) {
continue;
}
final Path parsed = PathFactory.createPath(this.getSession(), this.getAbsolute(), name,
final Path parsed = PathFactory.createPath(this.getSession(), this.getAbsolute(),
StringUtils.removeStart(name, this.getAbsolute() + Path.DELIMITER),
f.getType() == FTPFile.DIRECTORY_TYPE ? Path.DIRECTORY_TYPE : Path.FILE_TYPE);
parsed.setParent(this);
switch(f.getType()) {
Expand Down
19 changes: 19 additions & 0 deletions test/ch/cyberduck/core/ftp/FTPPathTest.java
Expand Up @@ -303,6 +303,25 @@ public void testParseUNIXPermissions() throws Exception {
}
}

public void testParseAbsolutePaths() throws Exception {
FTPPath path = (FTPPath) PathFactory.createPath(SessionFactory.createSession(new Host(Protocol.FTP, "localhost")),
"/data/FTP_pub", Path.DIRECTORY_TYPE);

{
final AttributedList<Path> children = new AttributedList<Path>();
String[] replies = new String[]{
"- [RWCEAFMS] Petersm 0 May 05 2004 /data/FTP_pub/WelcomeTo_PeakFTP"
};

boolean success = path.parseListResponse(children, new FTPParserFactory().createFileEntryParser("NETWARE Type : L8"),
Arrays.asList(replies));
assertTrue(success);
assertEquals(1, children.size());
assertEquals("WelcomeTo_PeakFTP", children.get(0).getName());
assertEquals("/data/FTP_pub", children.get(0).getParent().getAbsolute());
}
}

public static Test suite() {
return new TestSuite(FTPPathTest.class);
}
Expand Down
24 changes: 20 additions & 4 deletions test/ch/cyberduck/core/ftp/parser/NetwareFTPEntryParserTest.java
Expand Up @@ -29,7 +29,7 @@
import java.util.Calendar;

/**
* @version $Id:$
* @version $Id$
*/
public class NetwareFTPEntryParserTest extends AbstractTestCase {

Expand All @@ -43,7 +43,7 @@ public NetwareFTPEntryParserTest(String name) {
@Override
public void setUp() {
super.setUp();
this.parser = new FTPParserFactory().createFileEntryParser("NETWARE");
this.parser = new FTPParserFactory().createFileEntryParser("NETWARE Type : L8");
}

@Override
Expand All @@ -52,11 +52,11 @@ public void tearDown() throws Exception {
}

/**
* http://trac.cyberduck.ch/ticket/1996
* #1996
*
* @throws Exception
*/
public void testParse() throws Exception {
public void testDateYearParser() throws Exception {
FTPFile parsed;

parsed = parser.parseFTPEntry(
Expand Down Expand Up @@ -85,6 +85,22 @@ public void testParse() throws Exception {
assertTrue(parsed.getTimestamp().get(Calendar.DAY_OF_MONTH) == 1);
}

/**
* #5573
*
* @throws Exception
*/
public void testListingWithAbsolutePaths() throws Exception {
FTPFile parsed;

parsed = parser.parseFTPEntry(
"- [RWCEAFMS] Petersm 0 May 05 2004 /data/FTP_pub/WelcomeTo_PeakFTP"
);
assertNotNull(parsed);
assertEquals(parsed.getName(), "/data/FTP_pub/WelcomeTo_PeakFTP");
assertTrue(parsed.getType() == FTPFile.FILE_TYPE);
}

public static Test suite() {
return new TestSuite(NetwareFTPEntryParserTest.class);
}
Expand Down

0 comments on commit 4bfbe7a

Please sign in to comment.