dart-lang / dart-lang/http

Multipart form request with fields of the same name only retains one field value

Open
#277 6 comments 3 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
1.1k
Forks
419
Avg merge
4d 14h
Merged PRs (30d)
8

Description

With Multipart form data, it is allowed to have multiple fields of the same name with different values and they all are submitted to the server.

A curl example of that is below (from Mailgun API documentation):

```bash
curl -s --user 'api:YOUR_API_KEY' \
https://api.mailgun.net/v3/routes \
-F priority=0 \
-F description='Sample route' \
-F expression='match_recipient(".*@YOUR_DOMAIN_NAME")' \
-F action='forward("http://myhost.com/messages/")' \
-F action='stop()'
```

Here is the test case:
```dart
test('with multiple fields of the same name', () {
var request = http.MultipartRequest('POST', dummyUrl);
request.fields['field1'] = 'value1';
request.fields['field1'] = 'value2';

expect(request, bodyMatches('''
--{{boundary}}
content-disposition: form-data; name="field1"

value1
--{{boundary}}
content-disposition: form-data; name="field1"

value2
--{{boundary}}--
'''));
});
```

The above test case fails because we store fields in a Map and so `value2` replaces the previously set `value1` for `field1`.

Contributor guide

Open the contributing guide

Research direction

Start with MultipartRequest.fields and the multipart serialization path; the issue identifies the Map storage as the source of the replacement. Use the provided test case as the first check, and consider how repeated field names should be represented. Done means both values are emitted as separate multipart fields and the test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.