diff --git a/index.js b/index.js index d12518b..04d52eb 100644 --- a/index.js +++ b/index.js @@ -305,7 +305,8 @@ PQ.prototype.flush = function() { //escapes a literal and returns the escaped string //I'm not 100% sure this doesn't do any I/O...need to check that PQ.prototype.escapeLiteral = function(input) { - if(!input) return input; + if(input === null) return 'NULL'; + else if(input === undefined) return input; return this.$escapeLiteral(input); }; diff --git a/test/escaping.js b/test/escaping.js index acbb629..39df0a9 100644 --- a/test/escaping.js +++ b/test/escaping.js @@ -22,6 +22,27 @@ describe('escapeLiteral', function() { var result = pq.escapeLiteral("'; TRUNCATE TABLE blah;"); assert.equal(result, "'''; TRUNCATE TABLE blah;'"); }); + + it('escapes an empty string', function() { + var pq = new Libpq(); + pq.connectSync(); + var result = pq.escapeLiteral(""); + assert.equal(result, "''"); + }); + + it('escapes a null value', function() { + var pq = new Libpq(); + pq.connectSync(); + var result = pq.escapeLiteral(null); + assert.equal(result, "NULL"); + }); + + it('fails to escape an undefined value', function() { + var pq = new Libpq(); + pq.connectSync(); + var result = pq.escapeLiteral(); + assert.strictEqual(result, undefined); + }); }); describe('escapeIdentifier', function() {