edgurgel / edgurgel/httpoison

[bug] Multipart file with extra named fields fails to merge properly

Open
#489 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
2.3k
Forks
349
PR merge metrics
No merged PRs in 30d

Description

Hi there,

I was playing around to get the current example working, I kind of managed to, but whenever you need to send params named like the following example:

```
{:multipart, [
{"workspace[c_id]", "..."},
{"workspace[namespace_uuid]", "..."},
{"workspace[name]", "workspace name"},
{"workspace[demo]", "false"},
{:file, logo_file_path(), {"form-data", [name: "workspace[logo]", filename: Path.basename(logo_file_path())]}, []},
]}
```

what will get sent is the following:
```
{"workspace"=>{"filename"=>"logo.png", "type"=>"image/png", "name"=>"workspace", "tempfile"=>#, "head"=>"content-length: 9287\r\ncontent-type: image/png\r\ncontent-disposition: form-data; name=workspace[logo]; filename=logo.png\r\n"}}
```

now, the expected results ideally would have had also the other attributes under the `workspace[]` but they got lost apparently.

instead on this other example:
```
{:multipart, [
{"workspace[c_id]", "..."},
{"workspace[namespace_uuid]", "..."},
{"workspace[name]", "workspace name"},
{"workspace[demo]", "false"},
{:file, logo_file_path(), {"form-data", [name: "logo", filename: Path.basename(logo_file_path())]}, []},
]}
```

what will get sent is the following:
```
{"workspace"=>{"c_id"=>"...", "namespace_uuid"=>"....", "name"=>"workspace name", "demo"=>"false"}, "logo"=>{"filename"=>"logo.png", "type"=>"image/png", "name"=>"logo", "tempfile"=>#, "head"=>"content-length: 9287\r\ncontent-type: image/png\r\ncontent-disposition: form-data; name=logo; filename=logo.png\r\n"}}
```

which is correct.
so the issue is only on the first scenario

any hint would be grateful

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the two multipart examples from the issue and compare how the nested field names are handled when the file is named workspace[logo]. Trace the multipart request-building and field-merging path; done means the first payload preserves c_id, namespace_uuid, name, and demo under workspace alongside the file.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.