diff --git a/lib/client.js b/lib/client.js index 223ff0e9e..1ef0ac2f1 100644 --- a/lib/client.js +++ b/lib/client.js @@ -162,6 +162,8 @@ Client.prototype.format = function(sql, params) { }; Client.prototype.escape = function(val) { + var escape = this.escape; + if (val === undefined || val === null) { return 'NULL'; } @@ -171,6 +173,10 @@ Client.prototype.escape = function(val) { case 'number': return val+''; } + if (Array.isArray(val)) { + var sanitized = val.map( function( v ) { return escape( v ); } ); + return "'" + sanitized.join( "','" ) + "'"; + } if (typeof val === 'object') { val = (typeof val.toISOString === 'function') ? val.toISOString() diff --git a/test/unit/legacy/test-client.js b/test/unit/legacy/test-client.js index 4d116e092..4e3173182 100644 --- a/test/unit/legacy/test-client.js +++ b/test/unit/legacy/test-client.js @@ -41,7 +41,7 @@ test(function escape() { assert.equal(client.escape(true), 'true'); assert.equal(client.escape(5), '5'); assert.equal(client.escape({foo:'bar'}), "'[object Object]'"); - assert.equal(client.escape([1,2,3]), "'1,2,3'"); + assert.equal(client.escape([1,2,3]), "'1','2','3'"); assert.equal(client.escape(new Date(Date.UTC(2011,6,6,6,6,6,6))), "'2011-07-06T06:06:06.006Z'"); assert.equal(client.escape('Super'), "'Super'");