Different array parse behaviour of x-www-form-urlencoded between ExpressJS and rails
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.9k
- Forks
- 936
- PR merge metrics
- No merged PRs in 30d
Description
I use content-type: application/x-www-form-urlencoded to send POST request to backend server. The post body as follow:
listing[pictures][files][][name]=9ADDD7B1-FCFF-4538-916A-1E63DFB43A72&
listing[pictures][files][][name]=EFFE67B2-5D41-4B74-A33E-5963F54FAEC7&
listing[pictures][files][][name]=BBC9CB38-FE01-4F1A-AE37-7ED71F4B2CB5
In backend server, if I use ruby on rails, the POST will be parsed as follow:
"pictures"=>{
"files"=>[
{"name"=>"9ADDD7B1-FCFF-4538-916A-1E63DFB43A72"},
{"name"=>"EFFE67B2-5D41-4B74-A33E-5963F54FAEC7"},
{"name"=>"BBC9CB38-FE01-4F1A-AE37-7ED71F4B2CB5"}
]
}
This result is what I expected to be.
But, If I use nodeJS express and body-parser:
// parse application/json
app.use(bodyParser.json());
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
extended: true means that bodyParser will use qs to parse data.
The POST will be parsed as follow:
"pictures"=>{
"files"=>[
"name"=>[
"9ADDD7B1-FCFF-4538-916A-1E63DFB43A72",
"EFFE67B2-5D41-4B74-A33E-5963F54FAEC7",
"BBC9CB38-FE01-4F1A-AE37-7ED71F4B2CB5"
]
]
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied repeated-key payload through qs and bodyParser.urlencoded({ extended: true }), then compare its structure with the Rails result. Trace how the nested array notation is interpreted and establish whether the expected array-of-objects shape can be supported or should be documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, javascript, nodejs, rails
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100