Skip to content

Commit

Permalink
Use self.encoding when calling Buffer.toString()
Browse files Browse the repository at this point in the history
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
isaacs committed Aug 10, 2012
1 parent 820af58 commit 7adc5a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand Down
5 changes: 5 additions & 0 deletions tests/test-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7adc5a2

Please sign in to comment.