New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
corrupted multibyte characters in node #38
Comments
@vkurchatkin Would you mind providing example code so that I know how to reproduce this? |
Here it is var axios = require('axios');
var http = require('http');
var assert = require('assert');
var str = Array(100000).join('ж');
http.createServer(function(req, res) {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
res.end(str);
}).listen(4444, function() {
axios.get('http://localhost:4444/').then(function(response) {
process.nextTick(function() {
assert(response.data === str);
});
});
}); I'm not sure that this test is 100% reliable (or that a 100% reliable test of this exists at all) |
Thanks. I'll give this a look. |
Here is a quick fix: diff --git a/lib/adapters/http.js b/lib/adapters/http.js
index 8a6fbf6..81da7ac 100644
--- a/lib/adapters/http.js
+++ b/lib/adapters/http.js
@@ -52,15 +52,15 @@ module.exports = function httpAdapter(resolve, reject, config) {
// Create the request
var transport = parsed.protocol === 'https:' ? https : http;
var req = transport.request(options, function (res) {
- var responseText = '';
+ var responseBuffer = [];
res.on('data', function (chunk) {
- responseText += chunk;
+ responseBuffer.push(chunk);
});
res.on('end', function () {
var response = {
data: transformData(
- responseText,
+ Buffer.concat(responseBuffer).toString('utf8'),
res.headers,
config.transformResponse
),
@@ -83,4 +83,4 @@ module.exports = function httpAdapter(resolve, reject, config) {
// Send the request
req.end(data);
-};
\ No newline at end of file
+}; |
@vkurchatkin thank you for your diff. I will apply this and write some tests around it. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Multibyte characters on chunk boundaries get corrupted.
The text was updated successfully, but these errors were encountered: