This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
The following commit(s) were added to refs/heads/master by this push:
new d62fa7c9 Sort members
d62fa7c9 is described below
commit d62fa7c9f620c636e66ab475b30695f8f49acafd
Author: Gary D. Gregory <[email protected]>
AuthorDate: Fri May 2 20:46:15 2025 -0400
Sort members
---
.../fileupload2/core/AbstractRequestContext.java | 18 +--
.../fileupload2/core/MockRequestContextTest.java | 142 ++++++++++-----------
.../core/QuotedPrintableDecoderTestCase.java | 10 +-
3 files changed, 85 insertions(+), 85 deletions(-)
diff --git
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/AbstractRequestContext.java
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/AbstractRequestContext.java
index 63b4f2a5..fa4f9b74 100644
---
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/AbstractRequestContext.java
+++
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/AbstractRequestContext.java
@@ -76,23 +76,23 @@ public abstract class AbstractRequestContext<T> implements
RequestContext {
}
/**
- * Returns a string representation of this object.
+ * Is the Request of type {@code multipart/related}?
*
- * @return a string representation of this object.
+ * @return the Request is of type {@code multipart/related}
+ * @since 2.0.0
*/
@Override
- public String toString() {
- return String.format("%s [ContentLength=%s, ContentType=%s]",
getClass().getSimpleName(), getContentLength(), getContentType());
+ public boolean isMultipartRelated() {
+ return MULTIPART_RELATED.matcher(getContentType()).matches();
}
/**
- * Is the Request of type {@code multipart/related}?
+ * Returns a string representation of this object.
*
- * @return the Request is of type {@code multipart/related}
- * @since 2.0.0
+ * @return a string representation of this object.
*/
@Override
- public boolean isMultipartRelated() {
- return MULTIPART_RELATED.matcher(getContentType()).matches();
+ public String toString() {
+ return String.format("%s [ContentLength=%s, ContentType=%s]",
getClass().getSimpleName(), getContentLength(), getContentType());
}
}
diff --git
a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MockRequestContextTest.java
b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MockRequestContextTest.java
index c21e1540..d1a67a19 100644
---
a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MockRequestContextTest.java
+++
b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MockRequestContextTest.java
@@ -30,11 +30,59 @@ import static org.junit.jupiter.api.Assertions.*;
* Tests for {@link AbstractRequestContext}
*/
public class MockRequestContextTest {
+ private static final class MockRequestContext extends
AbstractRequestContext<Object> {
+ private final String characterEncoding;
+ private final String contentType;
+ private final InputStream inputStream;
+
+ private MockRequestContext(final Function<String, String>
contentLengthString,
+ final LongSupplier contentLengthDefault,
+ final Object request,
+ final String characterEncoding,
+ final String contentType,
+ final InputStream inputStream) {
+ super(contentLengthString, contentLengthDefault, request);
+ this.characterEncoding = characterEncoding;
+ this.contentType = contentType;
+ this.inputStream = inputStream;
+ }
+
+ /**
+ * Gets the character encoding for the request.
+ *
+ * @return The character encoding for the request.
+ */
+ @Override
+ public String getCharacterEncoding() {
+ return characterEncoding;
+ }
+
+ /**
+ * Gets the content type of the request.
+ *
+ * @return The content type of the request.
+ */
+ @Override
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * Gets the input stream for the request.
+ *
+ * @return The input stream for the request.
+ */
+ @Override
+ public InputStream getInputStream() {
+ return inputStream;
+ }
+ }
+
/**
- * Test if the {@code content-length} Value is numeric.
+ * Test if the given {@code character-encoding} is a valid CharEncoding
*/
@Test
- public void getContentLengthByParsing() {
+ public void getCharset() {
final RequestContext request = new MockRequestContext(
x -> "1234",
() -> 5678L,
@@ -42,38 +90,38 @@ public class MockRequestContextTest {
"US-ASCII",
"text/plain",
null);
- assertEquals(1234L, request.getContentLength());
+ assertEquals(StandardCharsets.US_ASCII, request.getCharset());
}
/**
- * Test if the {@code content-length} Value is not numeric
- * and the Default will be taken.
+ * Test if the {@code content-length} Value is numeric.
*/
@Test
- public void getContentLengthDefaultBecauseOfInvalidNumber() {
+ public void getContentLengthByParsing() {
final RequestContext request = new MockRequestContext(
- x -> "not-a-number",
+ x -> "1234",
() -> 5678L,
"Request",
"US-ASCII",
"text/plain",
null);
- assertEquals(5678L, request.getContentLength());
+ assertEquals(1234L, request.getContentLength());
}
/**
- * Test if the given {@code character-encoding} is a valid CharEncoding
+ * Test if the {@code content-length} Value is not numeric
+ * and the Default will be taken.
*/
@Test
- public void getCharset() {
+ public void getContentLengthDefaultBecauseOfInvalidNumber() {
final RequestContext request = new MockRequestContext(
- x -> "1234",
+ x -> "not-a-number",
() -> 5678L,
"Request",
"US-ASCII",
"text/plain",
null);
- assertEquals(StandardCharsets.US_ASCII, request.getCharset());
+ assertEquals(5678L, request.getContentLength());
}
/**
@@ -93,40 +141,40 @@ public class MockRequestContextTest {
}
/**
- * Test the {@code toString()} Output
+ * Test if the {@code content-type} is {@code multipart/related}
*/
@Test
- public void testToString() {
+ public void testIsMultipartRelated() {
final RequestContext request = new MockRequestContext(
x -> "1234",
() -> 5678L,
"Request",
"US-ASCII",
- "text/plain",
+ "multipart/related; boundary=---1234;
type=\"application/xop+xml\"; start-info=\"application/soap+xml\"",
null);
- assertEquals("MockRequestContext [ContentLength=1234,
ContentType=text/plain]", request.toString());
+ assertTrue(request.isMultipartRelated());
}
/**
- * Test if the {@code content-type} is {@code multipart/related}
+ * Test if the {@code content-type} is not {@code multipart/related}
*/
@Test
- public void testIsMultipartRelated() {
+ public void testIsNotMultipartRelated() {
final RequestContext request = new MockRequestContext(
x -> "1234",
() -> 5678L,
"Request",
"US-ASCII",
- "multipart/related; boundary=---1234;
type=\"application/xop+xml\"; start-info=\"application/soap+xml\"",
+ "text/plain",
null);
- assertTrue(request.isMultipartRelated());
+ assertFalse(request.isMultipartRelated());
}
/**
- * Test if the {@code content-type} is not {@code multipart/related}
+ * Test the {@code toString()} Output
*/
@Test
- public void testIsNotMultipartRelated() {
+ public void testToString() {
final RequestContext request = new MockRequestContext(
x -> "1234",
() -> 5678L,
@@ -134,54 +182,6 @@ public class MockRequestContextTest {
"US-ASCII",
"text/plain",
null);
- assertFalse(request.isMultipartRelated());
- }
-
- private static final class MockRequestContext extends
AbstractRequestContext<Object> {
- private final String characterEncoding;
- private final String contentType;
- private final InputStream inputStream;
-
- private MockRequestContext(final Function<String, String>
contentLengthString,
- final LongSupplier contentLengthDefault,
- final Object request,
- final String characterEncoding,
- final String contentType,
- final InputStream inputStream) {
- super(contentLengthString, contentLengthDefault, request);
- this.characterEncoding = characterEncoding;
- this.contentType = contentType;
- this.inputStream = inputStream;
- }
-
- /**
- * Gets the character encoding for the request.
- *
- * @return The character encoding for the request.
- */
- @Override
- public String getCharacterEncoding() {
- return characterEncoding;
- }
-
- /**
- * Gets the content type of the request.
- *
- * @return The content type of the request.
- */
- @Override
- public String getContentType() {
- return contentType;
- }
-
- /**
- * Gets the input stream for the request.
- *
- * @return The input stream for the request.
- */
- @Override
- public InputStream getInputStream() {
- return inputStream;
- }
+ assertEquals("MockRequestContext [ContentLength=1234,
ContentType=text/plain]", request.toString());
}
}
diff --git
a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/QuotedPrintableDecoderTestCase.java
b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/QuotedPrintableDecoderTestCase.java
index 149289f3..d633e1dd 100644
---
a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/QuotedPrintableDecoderTestCase.java
+++
b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/QuotedPrintableDecoderTestCase.java
@@ -103,6 +103,11 @@ public final class QuotedPrintableDecoderTestCase {
"If you believe that truth=3Dbeauty, then " +
"surely=20=\r\nmathematics is the most beautiful branch of philosophy.");
}
+ @Test
+ public void testTruncatedEscape() throws Exception {
+ assertIOException("truncated", "=1");
+ }
+
@Test
public void testUnsafeDecode() throws Exception {
assertEncoded("=\r\n", "=3D=0D=0A");
@@ -113,9 +118,4 @@ public final class QuotedPrintableDecoderTestCase {
assertEncoded("=\r\n", "=3d=0d=0a");
}
- @Test
- public void testTruncatedEscape() throws Exception {
- assertIOException("truncated", "=1");
- }
-
}