Skip to content

Commit a8da84c

Browse files
committed
NET-294 UnixFTPEntryParser fails to parse some entries
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/trunk@814451 13f79535-47bb-0310-9956-ffa450edef68
1 parent bf06da2 commit a8da84c

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,25 @@ public class UnixFTPEntryParser extends ConfigurableFTPFileEntryParserImpl
8888
private static final String REGEX =
8989
"([bcdlfmpSs-])"
9090
+"(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\+?\\s+"
91-
+ "(\\d+)\\s+"
92-
+ "(\\S+)\\s+"
93-
+ "(?:(\\S+(?:\\s\\S+)*)\\s+)?"
94-
+ "(\\d+(?:,\\s*\\d+)?)\\s+"
91+
+ "(\\d+)\\s+" // link count
92+
+ "(\\S+)\\s+" // owner name
93+
+ "(?:(\\S+(?:\\s\\S+)*)\\s+)?" // group name (optional spaces)
94+
+ "(\\d+(?:,\\s*\\d+)?)\\s+" // size or n,m
9595

9696
/*
97-
numeric or standard format date
97+
* numeric or standard format date:
98+
* yyyy-mm-dd (expecting hh:mm to follow)
99+
* MMMM [d]d
100+
* [d]d MMM
98101
*/
99-
+ "((?:\\d+[-/]\\d+[-/]\\d+)|(?:\\S+\\s+\\S+))\\s+"
100-
102+
+ "((?:\\d+[-/]\\d+[-/]\\d+)|(?:[a-zA-Z]{3}\\s+\\d{1,2})|(?:\\d{1,2}\\s+[a-zA-Z]{3}))\\s+"
101103
/*
102-
year (for non-recent standard format)
103-
or time (for numeric or recent standard format
104+
year (for non-recent standard format) - yyyy
105+
or time (for numeric or recent standard format [h]h:mm
104106
*/
105107
+ "(\\d+(?::\\d+)?)\\s+"
106108

107-
+ "(\\S*)(\\s*.*)";
109+
+ "(\\S*)(\\s*.*)"; // the rest
108110

109111

110112
/**

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

Lines changed: 16 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
};
@@ -233,6 +234,18 @@ public void testParseFieldsOnFile() throws Exception {
233234
assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp().getTime()));
234235
}
235236

237+
public void testNET294() {
238+
FTPFile f = getParser().parseFTPEntry(
239+
"-rwxrwx--- 1 ftp ftp-admin 816026400 Oct 5 2008 bloplab 7 cd1.img");
240+
assertNotNull(f);
241+
assertEquals("ftp", f.getUser());
242+
assertEquals("ftp-admin", f.getGroup());
243+
assertEquals(816026400L,f.getSize());
244+
assertNotNull("Timestamp should not be null",f.getTimestamp());
245+
assertEquals(2008,f.getTimestamp().get(Calendar.YEAR));
246+
assertEquals("bloplab 7 cd1.img",f.getName());
247+
}
248+
236249

237250
/**
238251
* Method suite.
@@ -268,6 +281,7 @@ protected void doAdditionalGoodTests(String test, FTPFile f) {
268281
case 'b':
269282
case 'c':
270283
assertEquals(0, f.getHardLinkCount());
284+
//$FALL-THROUGH$ TODO fix if DEVICE_TYPE introduced
271285
case 'f':
272286
case '-':
273287
assertEquals("Type of "+ test, type, FTPFile.FILE_TYPE);
@@ -290,5 +304,6 @@ protected void doAdditionalGoodTests(String test, FTPFile f) {
290304
}
291305
}
292306

307+
assertNotNull("Expecting valid timestamp",f.getTimestamp());
293308
}
294309
}

xdocs/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ limitations under the License.
104104
</action>
105105
<action dev="sebb" type="fix" issue="NET-225">
106106
FTPFileEntryParserImpl.preParse() doesn't remove unparsable entries at the end of the file list
107+
</action>
108+
<action dev="sebb" type="fix" issue="NET-294">
109+
UnixFTPEntryParser fails to parse some entries
107110
</action>
108111
</release>
109112

0 commit comments

Comments
 (0)