Skip to content
Permalink
Browse files
FILEUPLOAD-334 - LineLength - Line is longer than 120 characters
  • Loading branch information
arturobernalg committed May 16, 2021
1 parent 09d6305 commit 64caa719fb84bdf6054ee716184c66716e5538f0
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 23 deletions.
@@ -327,7 +327,8 @@ public List<FileItem> parseRequest(final RequestContext ctx)
boolean successful = false;
try {
final FileItemIterator iter = getItemIterator(ctx);
final FileItemFactory fileItemFactory = Objects.requireNonNull(getFileItemFactory(), "No FileItemFactory has been set.");
final FileItemFactory fileItemFactory = Objects.requireNonNull(getFileItemFactory(),
"No FileItemFactory has been set.");
final byte[] buffer = new byte[Streams.DEFAULT_BUFFER_SIZE];
while (iter.hasNext()) {
final FileItemStream item = iter.next();
@@ -336,7 +336,8 @@ public List<FileItem> getFileItems() throws FileUploadException, IOException {
final List<FileItem> items = new ArrayList<>();
while (hasNext()) {
final FileItemStream fis = next();
final FileItem fi = fileUploadBase.getFileItemFactory().createItem(fis.getFieldName(), fis.getContentType(), fis.isFormField(), fis.getName());
final FileItem fi = fileUploadBase.getFileItemFactory().createItem(fis.getFieldName(),
fis.getContentType(), fis.isFormField(), fis.getName());
items.add(fi);
}
return items;
@@ -62,7 +62,8 @@ private Streams() {
* @return Number of bytes, which have been copied.
* @throws IOException An I/O error occurred.
*/
public static long copy(final InputStream inputStream, final OutputStream outputStream, final boolean closeOutputStream)
public static long copy(final InputStream inputStream, final OutputStream outputStream,
final boolean closeOutputStream)
throws IOException {
return copy(inputStream, outputStream, closeOutputStream, new byte[DEFAULT_BUFFER_SIZE]);
}
@@ -22,7 +22,8 @@
* Utility class to decode/encode character set on HTTP Header fields based on RFC 2231.
* This implementation adheres to RFC 5987 in particular, which was defined for HTTP headers
*
* RFC 5987 builds on RFC 2231, but has lesser scope like <a href="https://tools.ietf.org/html/rfc5987#section-3.2">mandatory charset definition</a>
* RFC 5987 builds on RFC 2231, but has lesser scope like
* <a href="https://tools.ietf.org/html/rfc5987#section-3.2">mandatory charset definition</a>
* and <a href="https://tools.ietf.org/html/rfc5987#section-4">no parameter continuation</a>
*
* <p>
@@ -83,7 +84,8 @@ public static String stripDelimiter(final String paramName) {
* <b>Eg 3.</b> {@code UTF-8''%c2%a3%20and%20%e2%82%ac%20rates}
* will be decoded to {@code £ and € rates}.
*
* @param encodedText - Text to be decoded has a format of {@code <charset>'<language>'<encoded_value>} and ASCII only
* @param encodedText - Text to be decoded has a format of {@code <charset>'<language>'<encoded_value>}
* and ASCII only
* @return Decoded text based on charset encoding
* @throws UnsupportedEncodingException The requested character set wasn't found.
*/
@@ -38,7 +38,8 @@ public class FileItemHeadersTest {
@Test
public void testFileItemHeaders() throws Exception {
final FileItemHeadersImpl aMutableFileItemHeaders = new FileItemHeadersImpl();
aMutableFileItemHeaders.addHeader("Content-Disposition", "form-data; name=\"FileItem\"; filename=\"file1.txt\"");
aMutableFileItemHeaders.addHeader("Content-Disposition",
"form-data; name=\"FileItem\"; filename=\"file1.txt\"");
aMutableFileItemHeaders.addHeader("Content-Type", "text/plain");

aMutableFileItemHeaders.addHeader("TestHeader", "headerValue1");
@@ -52,7 +53,8 @@ public void testFileItemHeaders() throws Exception {
assertEquals("testheader", headerNameEnumeration.next());
assertFalse(headerNameEnumeration.hasNext());

assertEquals(aMutableFileItemHeaders.getHeader("Content-Disposition"), "form-data; name=\"FileItem\"; filename=\"file1.txt\"");
assertEquals(aMutableFileItemHeaders.getHeader("Content-Disposition"),
"form-data; name=\"FileItem\"; filename=\"file1.txt\"");
assertEquals(aMutableFileItemHeaders.getHeader("Content-Type"), "text/plain");
assertEquals(aMutableFileItemHeaders.getHeader("content-type"), "text/plain");
assertEquals(aMutableFileItemHeaders.getHeader("TestHeader"), "headerValue1");
@@ -58,7 +58,8 @@ public void testFileUpload(final FileUpload upload)
throws IOException, FileUploadException {
final List<FileItem> fileItems = Util.parseUpload(upload,
"-----1234\r\n" +
"Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +
"Content-Disposition: "
+ "form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +
"Content-Type: text/whatever\r\n" +
"\r\n" +
"This is the content of the file\n" +
@@ -107,7 +108,8 @@ public void testFilenameCaseSensitivity(final FileUpload upload)
throws IOException, FileUploadException {
final List<FileItem> fileItems = Util.parseUpload(upload,
"-----1234\r\n" +
"Content-Disposition: form-data; name=\"FiLe\"; filename=\"FOO.tab\"\r\n" +
"Content-Disposition: form-data; "
+ "name=\"FiLe\"; filename=\"FOO.tab\"\r\n" +
"Content-Type: text/whatever\r\n" +
"\r\n" +
"This is the content of the file\n" +
@@ -221,7 +223,8 @@ public void testFILEUPLOAD62(final FileUpload upload) throws Exception {
"...contents of file2.gif...\r\n" +
"--BbC04y--\r\n" +
"--AaB03x--";
final List<FileItem> fileItems = Util.parseUpload(upload, request.getBytes(StandardCharsets.US_ASCII), contentType);
final List<FileItem> fileItems = Util.parseUpload(upload, request.getBytes(StandardCharsets.US_ASCII),
contentType);
assertEquals(3, fileItems.size());
final FileItem item0 = fileItems.get(0);
assertEquals("field1", item0.getFieldName());
@@ -307,7 +310,8 @@ public void testFileUpload130(final FileUpload upload)
};
final List<FileItem> fileItems = Util.parseUpload(upload,
"-----1234\r\n" +
"Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +
"Content-Disposition: form-data; name=\"file\"; "
+ "filename=\"foo.tab\"\r\n" +
"Content-Type: text/whatever\r\n" +
headerNames[0] + ": " + headerValues[0] + "\r\n" +
"\r\n" +
@@ -113,7 +113,8 @@ public void testFileUpload139() {
@Test
public void testFileUpload199() {
final ParameterParser parser = new ParameterParser();
final String s = "Content-Disposition: form-data; name=\"file\"; filename=\"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n";
final String s = "Content-Disposition: form-data; name=\"file\"; filename=\"=?ISO-8859-"
+ "1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n";
final Map<String, String> params = parser.parse(s, new char[] { ',', ';' });
assertEquals("If you can read this you understand the example.", params.get("filename"));
}
@@ -127,7 +128,8 @@ public void testFileUpload274() {
final ParameterParser parser = new ParameterParser();

// Should parse a UTF-8 charset
String s = "Content-Disposition: form-data; name=\"file\"; filename*=UTF-8\'\'%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF\r\n";
String s = "Content-Disposition: form-data; "
+ "name=\"file\"; filename*=UTF-8\'\'%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF\r\n";
Map<String, String> params = parser.parse(s, new char[] { ',', ';' });
assertEquals("\u3053\u3093\u306B\u3061\u306F", params.get("filename")); //filename = "こんにちは" in japanese

@@ -39,7 +39,8 @@ public static List<FileItem> parseUpload(final FileUpload upload, final byte[] b
return parseUpload(upload, bytes, Constants.CONTENT_TYPE);
}

public static List<FileItem> parseUpload(final FileUpload upload, final byte[] bytes, final String contentType) throws FileUploadException {
public static List<FileItem> parseUpload(final FileUpload upload, final byte[] bytes, final String contentType)
throws FileUploadException {
final HttpServletRequest request = new MockHttpServletRequest(bytes, contentType);
return upload.parseRequest(new ServletRequestContext(request));
}
@@ -61,7 +61,8 @@ public MockPortletActionRequest(final byte[] requestData, final String contentTy
this(new ByteArrayInputStream(requestData), requestData.length, contentType);
}

public MockPortletActionRequest(final ByteArrayInputStream byteArrayInputStream, final int requestLength, final String contentType) {
public MockPortletActionRequest(final ByteArrayInputStream byteArrayInputStream,
final int requestLength, final String contentType) {
this.requestData = byteArrayInputStream;
length = requestLength;
this.contentType = contentType;
@@ -150,7 +150,8 @@ private static void assertEncoded(final String clearText, final String encoded)
assertArrayEquals(expected, actual);
}

private static void assertIOException(final String messageText, final String encoded) throws UnsupportedEncodingException {
private static void assertIOException(final String messageText, final String encoded)
throws UnsupportedEncodingException {
final ByteArrayOutputStream out = new ByteArrayOutputStream(encoded.length());
final byte[] encodedData = encoded.getBytes(StandardCharsets.US_ASCII);
try {
@@ -49,13 +49,15 @@ public void decodeUtf8Base64Encoded() throws Exception {
@Test
public void decodeIso88591Base64Encoded() throws Exception {
assertEncoded("If you can read this you understand the example.",
"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n");
"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= "
+ "=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n");
}

@Test
public void decodeIso88591Base64EncodedWithWhiteSpace() throws Exception {
assertEncoded("If you can read this you understand the example.",
"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\t \r\n =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n");
"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\t \r\n =?ISO-8859-"
+ "2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n");
}

private static void assertEncoded(final String expected, final String encoded) throws Exception {
@@ -80,8 +80,9 @@ public void invalidCharDecode() {
*/
@Test
public void softLineBreakDecode() throws Exception {
assertEncoded("If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy.",
"If you believe that truth=3Dbeauty, then surely=20=\r\nmathematics is the most beautiful branch of philosophy.");
assertEncoded("If you believe that truth=beauty, then surely mathematics is the most "
+ "beautiful branch of philosophy.", "If you believe that truth=3Dbeauty, then "
+ "surely=20=\r\nmathematics is the most beautiful branch of philosophy.");
}

@Test
@@ -110,7 +111,8 @@ private static void assertEncoded(final String clearText, final String encoded)
assertArrayEquals(expected, actual);
}

private static void assertIOException(final String messageText, final String encoded) throws UnsupportedEncodingException {
private static void assertIOException(final String messageText, final String encoded)
throws UnsupportedEncodingException {
final ByteArrayOutputStream out = new ByteArrayOutputStream(encoded.length());
final byte[] encodedData = encoded.getBytes(StandardCharsets.US_ASCII);
try {
@@ -28,7 +28,8 @@
/**
* The expected characters are encoded in UTF16, while the actual characters may be encoded in UTF-8/ISO-8859-1
*
* RFC 5987 recommends to support both UTF-8 & ISO 8859-1. Test values are taken from https://tools.ietf.org/html/rfc5987#section-3.2.2
* RFC 5987 recommends to support both UTF-8 & ISO 8859-1. Test values are taken
* from https://tools.ietf.org/html/rfc5987#section-3.2.2
*/
public final class RFC2231UtilityTestCase {

@@ -66,7 +67,8 @@ public void noNeedToDecode() throws Exception {

@Test
public void decodeUtf8() throws Exception {
assertEncoded("\u00a3 \u0061\u006e\u0064 \u20ac \u0072\u0061\u0074\u0065\u0073", "UTF-8''%c2%a3%20and%20%e2%82%ac%20rates"); //"£ and € rates"
assertEncoded("\u00a3 \u0061\u006e\u0064 \u20ac \u0072\u0061\u0074\u0065\u0073",
"UTF-8''%c2%a3%20and%20%e2%82%ac%20rates"); //"£ and € rates"
}

@Test

0 comments on commit 64caa71

Please sign in to comment.