Match RFC 2047 encoding token case-insensitively in decodeWord#476
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes RFC 2047 “encoded-word” decoding in MimeUtils.decodeWord by treating the encoding token (B/Q) case-insensitively, ensuring lower-case markers (b/q) decode correctly (e.g., for Content-Disposition filenames).
Changes:
- Update
decodeWordto compare the encoding token usingequalsIgnoreCasefor both Base64 (B) and quoted-printable (Q). - Add regression tests covering lower-case
bandqencoding markers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/MimeUtils.java | Makes RFC 2047 encoding token matching case-insensitive in decodeWord. |
| commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MimeUtilityTestCase.java | Adds tests to verify lower-case b/q markers decode correctly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // 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. |
Member
|
@alhudz Merged 🚀 Thank you, please port to 1.x. |
garydgregory
added a commit
that referenced
this pull request
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repro:Content-Disposition: attachment; filename="=?utf-8?b?ZXZpbC5leGU=?=", a valid RFC 2047 encoded-word that uses the lower-casebmarker.Expected:the filename decodes toevil.exe, matching the upper-case=?utf-8?B?...?=form.Actual:MimeUtils.decodeWordthrowsUnsupportedEncodingException, soParameterParserkeeps the raw value=?utf-8?b?ZXZpbC5leGU=?=. Lower-caseqbehaves the same way against theQmarker.Cause:the charset token is lower-cased before use, but the encoding token is compared case-sensitively withencoding.equals("B")/equals("Q"). RFC 2047 section 2 defines the encoding as case-independent (b==B,q==Q).Fix:compare the encoding token withequalsIgnoreCase, sob/qdecode identically toB/Q. Two regression tests cover the lower-case base64 and quoted-printable markers; both fail before the change.mvn; that'smvnon the command line by itself.