Author: sebb
Date: Wed Dec 10 14:27:10 2014
New Revision: 1644429
URL: http://svn.apache.org/r1644429
Log:
More parsing tests and fixes
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java?rev=1644429&r1=1644428&r2=1644429&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
Wed Dec 10 14:27:10 2014
@@ -16,9 +16,10 @@
*/
package org.apache.commons.net.ftp.parser;
-import java.text.ParseException;
+import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Locale;
@@ -139,7 +140,11 @@ public class MLSxEntryParser extends FTP
file.setSize(Long.parseLong(factvalue));
}
else if ("modify".equals(factname)) {
- file.setTimestamp(parseGMTdateTime(factvalue));
+ final Calendar parsed = parseGMTdateTime(factvalue);
+ if (parsed == null) {
+ return null;
+ }
+ file.setTimestamp(parsed);
}
else if ("type".equals(factname)) {
Integer intType = TYPE_TO_INT.get(valueLowerCase);
@@ -197,15 +202,17 @@ public class MLSxEntryParser extends FTP
// both timezones need to be set for the parse to work OK
sdf.setTimeZone(GMT);
GregorianCalendar gc = new GregorianCalendar(GMT);
- try {
- gc.setTime(sdf.parse(timestamp));
- if (!hasMillis) {
- gc.clear(Calendar.MILLISECOND); // flag up missing ms units
- }
- return gc;
- } catch (ParseException e) {
- return null;
+ ParsePosition pos = new ParsePosition(0);
+ sdf.setLenient(false); // We want to parse the whole string
+ final Date parsed = sdf.parse(timestamp, pos);
+ if (pos.getIndex() != timestamp.length()) {
+ return null; // did not fully parse the input
+ }
+ gc.setTime(parsed);
+ if (!hasMillis) {
+ gc.clear(Calendar.MILLISECOND); // flag up missing ms units
}
+ return gc;
}
// perm-fact = "Perm" "=" *pvals
Modified:
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java?rev=1644429&r1=1644428&r2=1644429&view=diff
==============================================================================
---
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java
(original)
+++
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java
Wed Dec 10 14:27:10 2014
@@ -35,6 +35,9 @@ public class MLSxEntryParserTest extends
"Type=dir missing-semicolon",
"Type= missing value and semicolon",
" ", // no path
+ "Modify=2014; Short stamp",
+ "Type=pdir;Modify=20141205180002Z; /trailing chars in Modify",
+ "Type=dir;Modify=2014102206510x2.999;UNIX.mode=0775; modify has
spurious chars",
};
private static final String[] goodsamples = {