2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-11 18:02:32 +03:00

Fixing response with utf-8 BOM can not parse to json (#2419)

* fix: remove byte order marker (UTF-8 BOM) when transform response

* fix: remove BOM only utf-8

* test: utf-8 BOM

* fix: incorrect param name

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Cr
2020-07-02 01:14:52 +08:00
committed by GitHub
parent c4300a88cf
commit 16aa2ce7fa
3 changed files with 38 additions and 1 deletions
+20
View File
@@ -74,6 +74,26 @@ describe('supports http with nodejs', function () {
});
});
it('should allow passing JSON with BOM', function (done) {
var data = {
firstName: 'Fred',
lastName: 'Flintstone',
emailAddr: 'fred@example.com'
};
server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'application/json;charset=utf-8');
var bomBuffer = Buffer.from([0xEF, 0xBB, 0xBF])
var jsonBuffer = Buffer.from(JSON.stringify(data));
res.end(Buffer.concat([bomBuffer, jsonBuffer]));
}).listen(4444, function () {
axios.get('http://localhost:4444/').then(function (res) {
assert.deepEqual(res.data, data);
done();
});
});
});
it('should redirect', function (done) {
var str = 'test response';