From ddeaebb39d7aa893d313796f780c85d376d1ddf8 Mon Sep 17 00:00:00 2001 From: AyrA Date: Thu, 13 Aug 2015 23:21:06 +0200 Subject: [PATCH] proper UTF-8 handling This code properly handles UTF-8 server responses and prevents double encoding. --- lib/connection.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 94fcae0..643827c 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -431,14 +431,14 @@ FTP.prototype.list = function(path, zcomp, cb) { return cb(); } - var sockerr, done = false, replies = 0, entries, buffer = '', source = sock; + var sockerr, done = false, replies = 0, entries, buffer = [], source = sock; if (zcomp) { source = zlib.createInflate(); sock.pipe(source); } - source.on('data', function(chunk) { buffer += chunk.toString('binary'); }); + source.on('data', function(chunk) { buffer.push(chunk); }); source.once('error', function(err) { if (!sock.aborting) sockerr = err; @@ -452,6 +452,7 @@ FTP.prototype.list = function(path, zcomp, cb) { } function final() { if (done && replies === 2) { + buffer = Buffer.concat(buffer).toString(); replies = 3; if (sockerr) return cb(new Error('Unexpected data connection error: ' + sockerr));