mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Fixed toFormData regression bug (unreleased) with Array-like objects serialization; (#4714)
Added `toURLEncodedForm` helper; Added automatic payload serialization to `application/x-www-form-urlencoded` to have parity with `multipart/form-data`; Added test of handling `application/x-www-form-urlencoded` body by express.js; Updated README.md; Added missed param in JSDoc; Fixed hrefs in README.md; Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -12,8 +12,9 @@ var server, proxy;
|
||||
var AxiosError = require('../../../lib/core/AxiosError');
|
||||
var FormData = require('form-data');
|
||||
var formidable = require('formidable');
|
||||
const express = require('express');
|
||||
const multer = require('multer');
|
||||
var express = require('express');
|
||||
var multer = require('multer');
|
||||
var bodyParser = require('body-parser');
|
||||
|
||||
describe('supports http with nodejs', function () {
|
||||
|
||||
@@ -1337,9 +1338,11 @@ describe('supports http with nodejs', function () {
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toFormData helper', function () {
|
||||
it('should properly serialize nested objects for parsing with multer.js (express.js)', function (done) {
|
||||
const app = express();
|
||||
var app = express();
|
||||
|
||||
var obj = {
|
||||
arr1: ['1', '2', '3'],
|
||||
arr2: ['1', ['2'], '3'],
|
||||
@@ -1374,4 +1377,35 @@ describe('supports http with nodejs', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('URLEncoded Form', function () {
|
||||
it('should post object data as url-encoded form if content-type is application/x-www-form-urlencoded', function (done) {
|
||||
var app = express();
|
||||
|
||||
var obj = {
|
||||
arr1: ['1', '2', '3'],
|
||||
arr2: ['1', ['2'], '3'],
|
||||
obj: {x: '1', y: {z: '1'}},
|
||||
users: [{name: 'Peter', surname: 'griffin'}, {name: 'Thomas', surname: 'Anderson'}]
|
||||
};
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
app.post('/', function (req, res, next) {
|
||||
res.send(JSON.stringify(req.body));
|
||||
});
|
||||
|
||||
server = app.listen(3001, function () {
|
||||
return axios.post('http://localhost:3001/', obj, {
|
||||
headers: {
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
})
|
||||
.then(function (res) {
|
||||
assert.deepStrictEqual(res.data, obj);
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user