Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FormData clone boundary inconsistency issue #2305

Merged
merged 8 commits into from
Nov 11, 2024
1 change: 1 addition & 0 deletions dio/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See the [Migration Guide][] for the complete breaking changes list.**

- Update comments and strings with `MultipartFile`.
- Removes redundant warnings when composing request options on Web.
- Fixes boundary inconsistency in `FormData.clone()`.

## 5.7.0

Expand Down
3 changes: 2 additions & 1 deletion dio/lib/src/form_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class FormData {
///
/// See also: https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
String get boundary => _boundary;
late final String _boundary;
late String _boundary;

/// The form fields to send for this request.
final fields = <MapEntry<String, String>>[];
Expand Down Expand Up @@ -210,6 +210,7 @@ class FormData {
// Convenience method to clone finalized FormData when retrying requests.
FormData clone() {
final clone = FormData();
clone._boundary = _boundary;
clone.fields.addAll(fields);
for (final file in files) {
clone.files.add(MapEntry(file.key, file.value.clone()));
Expand Down
1 change: 1 addition & 0 deletions dio/test/formdata_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void main() async {
expect(fm1 != fm, true);
expect(fm1.files[0].value.filename, fm.files[0].value.filename);
expect(fm1.fields, fm.fields);
expect(fm1.boundary, fm.boundary);
},
testOn: 'vm',
);
Expand Down