This is an automated email from the ASF dual-hosted git repository.

garydgregory 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 b44c5e84 Match RFC 2047 encoding token case-insensitively in 
decodeWord (#476)
b44c5e84 is described below

commit b44c5e847c3ef4d6d9313ad8cc2dbaf01d294574
Author: alhuda <[email protected]>
AuthorDate: Mon Jul 13 20:35:28 2026 +0530

    Match RFC 2047 encoding token case-insensitively in decodeWord (#476)
---
 .../java/org/apache/commons/fileupload2/core/MimeUtils.java  |  6 +++---
 .../apache/commons/fileupload2/core/MimeUtilityTestCase.java | 12 ++++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git 
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/MimeUtils.java
 
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/MimeUtils.java
index 37f96010..0cd0e847 100644
--- 
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/MimeUtils.java
+++ 
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/MimeUtils.java
@@ -224,10 +224,10 @@ final class MimeUtils {
 
             final var encodedData = 
encodedText.getBytes(StandardCharsets.US_ASCII);
 
-            // Base64 encoded?
-            if (encoding.equals(BASE64_ENCODING_MARKER)) {
+            // Base64 encoded? RFC 2047 section 2 defines the encoding token 
as case-independent, so 'b' and 'q' are also valid.
+            if (encoding.equalsIgnoreCase(BASE64_ENCODING_MARKER)) {
                 out.write(Base64.getMimeDecoder().decode(encodedData));
-            } else if (encoding.equals(QUOTEDPRINTABLE_ENCODING_MARKER)) { // 
maybe quoted printable.
+            } else if 
(encoding.equalsIgnoreCase(QUOTEDPRINTABLE_ENCODING_MARKER)) { // maybe quoted 
printable.
                 QuotedPrintableDecoder.decode(encodedData, out);
             } else {
                 throw new UnsupportedEncodingException("Unknown RFC 2047 
encoding: " + encoding);
diff --git 
a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MimeUtilityTestCase.java
 
b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MimeUtilityTestCase.java
index 9186b9b6..62867c5d 100644
--- 
a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MimeUtilityTestCase.java
+++ 
b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MimeUtilityTestCase.java
@@ -54,11 +54,23 @@ public final class MimeUtilityTestCase {
         assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", 
"=?UTF-8?B?IGjDqSEgw6DDqMO0dSAhISE=?=");
     }
 
+    @Test
+    void testDecodeUtf8Base64EncodedLowerCaseMarker() throws Exception {
+        // RFC 2047 section 2: the encoding token is case-independent, so 'b' 
decodes like 'B'.
+        assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", 
"=?UTF-8?b?IGjDqSEgw6DDqMO0dSAhISE=?=");
+    }
+
     @Test
     void testDecodeUtf8QuotedPrintableEncoded() throws Exception {
         assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", 
"=?UTF-8?Q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?=");
     }
 
+    @Test
+    void testDecodeUtf8QuotedPrintableEncodedLowerCaseMarker() throws 
Exception {
+        // RFC 2047 section 2: the encoding token is case-independent, so 'q' 
decodes like 'Q'.
+        assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", 
"=?UTF-8?q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?=");
+    }
+
     @Test
     void testNoNeedToDecode() throws Exception {
         assertEncoded("abc", "abc");

Reply via email to