Skip to content

Commit 4654863

Browse files
committed
NET-294 UnixFTPEntryParser fails to parse some entries
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/branches/NET_2_0@814446 13f79535-47bb-0310-9956-ffa450edef68
1 parent 06d7e6e commit 4654863

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/main/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,24 @@ public class UnixFTPEntryParser extends ConfigurableFTPFileEntryParserImpl
8484
private static final String REGEX =
8585
"([bcdelfmpSs-])"
8686
+"(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\+?\\s*"
87-
+ "(\\d+)\\s+"
87+
+ "(\\d+)\\s+" // link count
8888
+ "(?:(\\S+(?:\\s\\S+)*?)\\s+)?" // owner name (optional spaces)
8989
+ "(?:(\\S+(?:\\s\\S+)*)\\s+)?" // group name (optional spaces)
90-
+ "(\\d+(?:,\\s*\\d+)?)\\s+"
90+
+ "(\\d+(?:,\\s*\\d+)?)\\s+" // size or n,m
9191
/*
92-
numeric or standard format date
92+
* numeric or standard format date:
93+
* yyyy-mm-dd (expecting hh:mm to follow)
94+
* MMMM [d]d
95+
* [d]d MMM
9396
*/
94-
+ "((?:\\d+[-/]\\d+[-/]\\d+)|(?:[a-zA-Z0-9]+\\s+\\S+))\\s+"
97+
+ "((?:\\d+[-/]\\d+[-/]\\d+)|(?:[a-zA-Z]{3}\\s+\\d{1,2})|(?:\\d{1,2}\\s+[a-zA-Z]{3}))\\s+"
9598
/*
96-
year (for non-recent standard format)
97-
or time (for numeric or recent standard format
99+
year (for non-recent standard format) - yyyy
100+
or time (for numeric or recent standard format) [h]h:mm
98101
*/
99102
+ "(\\d+(?::\\d+)?)\\s+"
100103

101-
+ "(\\S*)(\\s*.*)";
104+
+ "(\\S*)(\\s*.*)"; // the rest
102105

103106

104107
/**
@@ -186,6 +189,7 @@ public FTPFile parseFTPEntry(String entry) {
186189
case 'c':
187190
isDevice = true;
188191
// break; - fall through
192+
//$FALL-THROUGH$ TODO change this if DEVICE_TYPE implemented
189193
case 'f':
190194
case '-':
191195
type = FTPFile.FILE_TYPE;

src/site/xdoc/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ limitations under the License.
9999
<action dev="rwinston" type="fix">
100100
Fix inconsistent handling of socket read/write buffer size
101101
</action>
102+
<action dev="sebb" type="fix" issue="NET-294">
103+
UnixFTPEntryParser fails to parse some entries
104+
</action>
102105
</release>
103106

104107
<release version="2.0" date="October 20, 2008" description="Java 5.0 release">

src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public class UnixFTPEntryParserTest extends FTPParseTestFramework {
7474
"lrwxrwxrwx 1 neeme neeme 23 Mar 2 18:06 macros -> ./../../global/macros/.",
7575
"-rw-r--r-- 1 ftp group with spaces in it as allowed in cygwin see bug 38634 83853 Jan 22 2001 zxJDBC-1.2.4.tar.gz",
7676
"crw-r----- 1 root kmem 0, 27 Jan 30 11:42 kmem", //FreeBSD device
77-
"crw------- 1 root sys 109,767 Jul 2 2004 pci@1c,600000:devctl" //Solaris device
77+
"crw------- 1 root sys 109,767 Jul 2 2004 pci@1c,600000:devctl", //Solaris device
78+
"-rwxrwx--- 1 ftp ftp-admin 816026400 Oct 5 2008 bloplab 7 cd1.img", // NET-294
7879

7980

8081
};
@@ -158,6 +159,18 @@ public void testOwnerAndGroupNameWithSpaces() {
158159
assertEquals("test group", f.getGroup());
159160
}
160161

162+
public void testNET294() {
163+
FTPFile f = getParser().parseFTPEntry(
164+
"-rwxrwx--- 1 ftp ftp-admin 816026400 Oct 5 2008 bloplab 7 cd1.img");
165+
assertNotNull(f);
166+
assertEquals("ftp", f.getUser());
167+
assertEquals("ftp-admin", f.getGroup());
168+
assertEquals(816026400L,f.getSize());
169+
assertNotNull("Timestamp should not be null",f.getTimestamp());
170+
assertEquals(2008,f.getTimestamp().get(Calendar.YEAR));
171+
assertEquals("bloplab 7 cd1.img",f.getName());
172+
}
173+
161174
public void testGroupNameWithSpaces() {
162175
FTPFile f = getParser().parseFTPEntry("drwx------ 4 maxm Domain Users 512 Oct 2 10:59 .metadata");
163176
assertNotNull(f);
@@ -343,6 +356,7 @@ protected void doAdditionalGoodTests(String test, FTPFile f) {
343356
case 'b':
344357
case 'c':
345358
assertEquals(0, f.getHardLinkCount());
359+
//$FALL-THROUGH$ TODO this needs to be fixed if a device type is introduced
346360
case 'f':
347361
case '-':
348362
assertEquals("Type of "+ test, type, FTPFile.FILE_TYPE);
@@ -365,5 +379,8 @@ protected void doAdditionalGoodTests(String test, FTPFile f) {
365379
}
366380
}
367381

382+
assertNotNull("Expected to find a timestamp",f.getTimestamp());
383+
// Perhaps check date range (need to ensure all good examples qualify)
384+
// assertTrue(test,f.getTimestamp().get(Calendar.YEAR)>=2000);
368385
}
369386
}

0 commit comments

Comments
 (0)