🐛 Fix FormData.clone() dropping boundaryName and camelCaseContentDisposition#2531
Open
ultramcu wants to merge 1 commit into
Open
🐛 Fix FormData.clone() dropping boundaryName and camelCaseContentDisposition#2531ultramcu wants to merge 1 commit into
ultramcu wants to merge 1 commit into
Conversation
…osition cfug#2305 made clone() preserve the boundary value but still constructed the clone via the no-arg `FormData()` ctor, which silently reset two constructor options: - `boundaryName` — exposed via the `boundaryName` getter; useful to callers that key behaviour off a custom boundary label. - `camelCaseContentDisposition` (added in cfug#2008) — opts the multipart body into the `Content-Disposition` header casing required by some servers. The second is the user-visible regression: a multipart request retried via a cloned FormData emits `content-disposition` (lower-case) even when the original was configured with the camel-case opt-in, breaking servers that match the header case-sensitively. Forward both options when constructing the clone, and add a regression test covering the boundary name, the getter values, and the on-wire header casing.
Contributor
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is |
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.
Follow-on to merged #2305 and merged #2008.
FormData.clone()still drops two of the original constructor options, so a retried multipart request silently re-serialises with the defaults.1. Bug
clone()builds the new instance via the no-argFormData()constructor:That resets two options that the original may have set:
boundaryNameclone.boundaryNamereturns the dio default, not the user's labelcamelCaseContentDispositioncontent-disposition: form-data; …instead ofContent-Disposition: …The header-casing regression is the user-visible one: any server that matches
Content-Dispositioncase-sensitively (some signing gateways, some upload validators) accepts the first attempt and rejects the retry.2. Fix
Forward both options through
clone():One-line behavioural change, no new public API.
3. Test
New regression test in
dio/test/formdata_test.dart(clone() preserves boundaryName and camelCaseContentDisposition):FormDatawithboundaryName: '--custom-boundary'andcamelCaseContentDisposition: true,readAsBytes()on the clone and asserts the body containsContent-Disposition: form-data; name="name"and does not contain the lower-casecontent-disposition:form.Fail-before / pass-after verified locally:
content-disposition:lower-case).dio/test/formdata_test.dartsuite green (8/8).4. CI
dart format --output=none --set-exit-if-changed .ondio/— clean (0 of 63 files changed).dart analyzeondio/lib/src/form_data.dartanddio/test/formdata_test.dart— no issues.dart teston thedio/package — 220 passed / 6 network-gated skipped / 0 failed.New Pull Request Checklist
mainbranch to avoid conflicts (via merge from master or rebase)CHANGELOG.mdin the corresponding package