Browse files

Use self.encoding when calling Buffer.toString()

This is a bug resulting in getting UTF-8 mangled data in a callback when
explicitly setting an encoding to 'ascii' or 'binary'.
  • Loading branch information...
1 parent 820af58 commit 7adc5a21869bc92cc3b5e84d32c585952c8e5e87 @isaacs isaacs committed Aug 10, 2012
Showing with 6 additions and 1 deletion.
  1. +1 −1 main.js
  2. +5 −0 tests/test-body.js
View
2 main.js
@@ -618,7 +618,7 @@ Request.prototype.start = function () {
if (self.encoding === null) {
response.body = body
} else {
- response.body = body.toString()
+ response.body = body.toString(self.encoding)
}
} else if (buffer.length) {
response.body = buffer.join('')
View
5 tests/test-body.js
@@ -30,6 +30,11 @@ var tests =
, encoding: null
, expectBody: new Buffer("TESTING!")
}
+ , testGetEncoding :
+ { resp : server.createGetResponse(new Buffer('efa3bfcea9e29883', 'hex'))
+ , encoding: 'hex'
+ , expectBody: "efa3bfcea9e29883"
+ }
, testGetJSON :
{ resp : server.createGetResponse('{"test":true}', 'application/json')
, json : true

0 comments on commit 7adc5a2

Please sign in to comment.