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 2014/03/05 17:59:02 UTC
svn commit: r1574571 - in /commons/proper/net/trunk/src: changes/changes.xml
main/java/org/apache/commons/net/ftp/parser/NTFTPEntryParser.java
test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java
Author: sebb
Date: Wed Mar 5 16:59:02 2014
New Revision: 1574571
URL: http://svn.apache.org/r1574571
Log:
NET-516 parser problem occurs if the filename contains one or more characters of which the second byte of Shift-JIS code is 0x85
Fix NT parser
Modified:
commons/proper/net/trunk/src/changes/changes.xml
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/NTFTPEntryParser.java
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.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=1574571&r1=1574570&r2=1574571&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/net/trunk/src/changes/changes.xml [utf-8] Wed Mar 5 16:59:02 2014
@@ -65,6 +65,10 @@ The <action> type attribute can be add,u
<release version="3.4" date="2014-01-??" description="
This is mainly a bug-fix release. See further details below.
">
+ <action issue="NET-516" type="fix" dev="sebb" due-to="Asha K S & pavan">
+ parser problem occurs if the filename contains one or more characters of which the second byte of Shift-JIS code is 0x85
+ Fix NT parser
+ </action>
<action type="update" dev="sebb">
Added control encoding option to FTPClientExample
</action>
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/NTFTPEntryParser.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/NTFTPEntryParser.java?rev=1574571&r1=1574570&r2=1574571&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/NTFTPEntryParser.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/NTFTPEntryParser.java Wed Mar 5 16:59:02 2014
@@ -17,6 +17,7 @@
package org.apache.commons.net.ftp.parser;
import java.text.ParseException;
+import java.util.regex.Pattern;
import org.apache.commons.net.ftp.Configurable;
import org.apache.commons.net.ftp.FTPClientConfig;
@@ -76,7 +77,7 @@ public class NTFTPEntryParser extends Co
*/
public NTFTPEntryParser(FTPClientConfig config)
{
- super(REGEX);
+ super(REGEX, Pattern.DOTALL);
configure(config);
FTPClientConfig config2 = new FTPClientConfig(
FTPClientConfig.SYST_NT,
Modified: commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java?rev=1574571&r1=1574570&r2=1574571&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java (original)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java Wed Mar 5 16:59:02 2014
@@ -16,10 +16,12 @@
*/
package org.apache.commons.net.ftp.parser;
+import java.io.ByteArrayInputStream;
import java.util.Calendar;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPFileEntryParser;
+import org.apache.commons.net.ftp.FTPListParseEngine;
/**
* @author <a href="mailto:scohen@apache.org">Steve Cohen</a>
@@ -250,4 +252,93 @@ public class NTFTPEntryParserTest extend
assertEquals("Domain Users", f.getGroup());
}
+ // byte -123 when read using ISO-8859-1 encoding becomes 0X85 line terminator
+ private static final byte[] listFilesByteTrace = {
+ 48, 57, 45, 48, 52, 45, 49, 51, 32, 32, 48, 53, 58, 53, 49, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 60, 68, 73, 82, 62, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
+ 97, 115, 112, 110, 101, 116, 95, 99, 108, 105, 101, 110, 116,
+ 13, 10, // 1
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 50, 58, 53, 52, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 50, 32,
+ 65, 95, 113, 117, 105, 99, 107, 95, 98, 114, 111, 119, 110, 95, 102, 111, 120, 95, 106, 117, 109, 112, 115,
+ 95, 111, 118, 101, 114, 95, 116, 104, 101, 95, 108, 97, 122, 121, 95, 100, 111, 103,
+ 13, 10, // 2
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 50, 58, 49, 55, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 51, 32,
+ 120, -127, -123, 121,
+ 13, 10, // 3
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 49, 58, 52, 57, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 52, 32,
+ -126, -28, -126, -83, -119, -51, -126, -52, -105, -84, -126, -22, -126, -51,
+ -112, -30, -126, -90, -126, -72, -126, -75, -126, -60, -127, 65, -126, -75, -126, -87, -126, -32, -126,
+ -32, -126, -58, -126, -52, -112, -123, -126, -55, -126, -96, -126, -25, -126, -72, 46, 116, 120, 116,
+ 13, 10, // 4
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 50, 58, 52, 54, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 53, 32,
+ -125, 76, -125, -125, -125, 98, -125, 86, -125, 116, -125, -115, -127, 91, -116, 118, -114, 90, -113, -111,
+ 13, 10, // 5
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 50, 58, 52, 54, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 54, 32,
+ -125, 76, -125, -125, -125, 98, -125, 86, -125, -123, -125, 116, -125, -115, -127, 91, -116, 118, -114, 90, -113, -111,
+ 13, 10, // 6
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 49, 58, 52, 57, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 55, 32,
+ -114, 79, -116, -38, -126, -52, -105, -25, 46, 116, 120, 116,
+ 13, 10, // 7
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 49, 58, 52, 57, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 56, 32,
+ -111, -66, -116, -10, -106, 93, 46, 116, 120, 116,
+ 13, 10, // 8
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 50, 58, 53, 52, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 57, 32,
+ -113, -84, -106, -20, -106, -123, -114, 113,
+ 13, 10, // 9
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 49, 58, 52, 57, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 48, 32,
+ -119, -28, -109, 99, -118, -108, -114, -82, -119, -17, -114, -48, -120, -8, -112, -123, -108, 95, -117, -58, 46, 80, 68, 70,
+ 13, 10, // 10
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 50, 58, 49, 49, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 49, 32,
+ -112, -124, -99, -56, 46, 116, 120, 116,
+ 13, 10, // 11
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 50, 58, 52, 51, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 50, 32,
+ -117, -76, -116, -123,
+ 13, 10, // 12
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 50, 58, 49, 50, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 51, 32,
+ -114, -107, -111, -123, -108, 94, -104, 82,
+ 13, 10, //13
+ 48, 55, 45, 48, 51, 45, 49, 51, 32, 32, 48, 50, 58, 51, 53, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 52, 32,
+ -112, -123, -117, -101, -126, -52, -116, -16, -126, -19, -126, -24, 46, 116, 120, 116,
+ 13, 10, // 14
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 50, 58, 49, 50, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 53, 32,
+ -114, -123, -117, -101, -112, -20,
+ 13, 10, //15
+ 48, 55, 45, 49, 55, 45, 49, 51, 32, 32, 48, 49, 58, 52, 57, 80, 77,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 49, 54, 32,
+ -107, -94, -112, -123, -106, 126, -126, -55, -107, -44, -126, -25, -126, -72, 46, 116, 120, 116,
+ 13, 10 // 16
+ };
+
+ private static final int LISTFILE_COUNT = 16;
+
+ private int testNET516(String charset) throws Exception {
+ FTPFileEntryParser parser = new NTFTPEntryParser();
+ FTPListParseEngine engine = new FTPListParseEngine(parser );
+ engine.readServerList(new ByteArrayInputStream(listFilesByteTrace),charset);
+ FTPFile[] ftpfiles = engine.getFiles();
+ return ftpfiles.length;
+ }
+
+ public void testNET516() throws Exception { // problem where part of a multi-byte char gets converted to 0x85 = line term
+ int utf = testNET516("UTF-8");
+ assertEquals(LISTFILE_COUNT, utf);
+ int ascii = testNET516("ASCII");
+ assertEquals(LISTFILE_COUNT, ascii);
+ int iso8859_1 = testNET516("ISO-8859-1");
+ assertEquals(LISTFILE_COUNT, iso8859_1);
+ }
}