Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-03-14 19:59:07 +0400
committerBen Noordhuis <info@bnoordhuis.nl>2013-03-25 16:23:17 +0400
commit44843a60629ab5951a9c54ac6bf74208d607e3e0 (patch)
treeac3b8cd6b353b017c7eb73d379976db750c7baa1 /lib
parent05bd6b7bcd5e1e962413afe66564f2b60b0178e6 (diff)
child_process: fix sending utf-8 to child process
In process#send() and child_process.ChildProcess#send(), use 'utf8' as the encoding instead of 'ascii' because 'ascii' mutilates non-ASCII input. Correctly handle partial character sequences by introducing a StringDecoder. Sending over UTF-8 no longer works in v0.10 because the high bit of each byte is now cleared when converting a Buffer to ASCII. See commit 96a314b for details. Fixes #4999 and #5011.
Diffstat (limited to 'lib')
-rw-r--r--lib/child_process.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index 80735d4d0c2..52435913e94 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -19,6 +19,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
+var StringDecoder = require('string_decoder').StringDecoder;
var EventEmitter = require('events').EventEmitter;
var net = require('net');
var dgram = require('dgram');
@@ -321,11 +322,12 @@ function handleMessage(target, message, handle) {
function setupChannel(target, channel) {
target._channel = channel;
+ var decoder = new StringDecoder('utf8');
var jsonBuffer = '';
channel.buffering = false;
channel.onread = function(pool, offset, length, recvHandle) {
if (pool) {
- jsonBuffer += pool.toString('ascii', offset, offset + length);
+ jsonBuffer += decoder.write(pool.slice(offset, offset + length));
var i, start = 0;