diff --git a/lib/Connection.js b/lib/Connection.js index 7bde6e7..8a2e1a5 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -310,20 +310,21 @@ Connection.prototype.id = function(identification, cb) { if (!this.serverSupports('ID')) throw new Error('Server does not support ID'); var cmd = 'ID'; - if (identification === null) + if ((identification === null) || (Object.keys(identification).length === 0)) cmd += ' NIL'; else { if (Object.keys(identification).length > 30) throw new Error('Max allowed number of keys is 30'); - cmd += ' ('; + var kv = []; for (var k in identification) { - if (k.length > 30) + if (Buffer.byteLength(k) > 30) throw new Error('Max allowed key length is 30'); - if (identification[k].length > 1024) + if (Buffer.byteLength(identification[k]) > 1024) throw new Error('Max allowed value length is 1024'); - cmd += '"' + escape(k) + '" "' + escape(identification[k]) + '"'; + kv.push('"' + escape(k) + '"'); + kv.push('"' + escape(identification[k]) + '"'); } - cmd += ')'; + cmd += ' (' + kv.join(' ') + ')'; } this._enqueue(cmd, cb); };