fix: Add RFC 5987 filename* encoding for special characters#600
Open
abhu85 wants to merge 3 commits into
Open
Conversation
Per RFC 5987, characters like parentheses, spaces, quotes, and non-ASCII characters should be percent-encoded in the `filename*` parameter. This change: - Adds `filename*=utf-8''...` with proper percent-encoding when the filename contains characters outside the RFC 5987 attr-char set - Properly escapes double quotes and backslashes in the `filename="..."` parameter for backwards compatibility - Maintains simple `filename="..."` format for filenames that don't need encoding Fixes form-data#572 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Fixes #572 - Invalid Content-Disposition with FileName* containing parenthesis
This PR adds RFC 5987-compliant
filename*encoding for filenames containing special characters. When a filename contains characters that are not in the RFC 5987attr-charset (parentheses, spaces, quotes, non-ASCII, etc.), the_getContentDispositionmethod now outputs both:filename="..."- with quotes/backslashes escaped for backwards compatibilityfilename*=utf-8''...- with proper percent-encoding per RFC 5987Changes
isAttrChar()helper to check if a character is safe per RFC 5987encodeRfc5987()to percent-encode filenames using UTF-8needsRfc5987Encoding()to detect when encoding is needed_getContentDisposition()to:filenameparameterfilename*parameter when special characters are presentRFC References
Test Cases
Added comprehensive tests for:
test(1).txtfile name.txtsimple.txttest"quotes".txttest\slash.txt日本語.txtAll 29 existing tests continue to pass.