Validate docName parameter to avoid db delete
Project: http://git-wip-us.apache.org/repos/asf/couchdb-nano/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-nano/commit/3db2d953 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-nano/tree/3db2d953 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-nano/diff/3db2d953 Branch: refs/heads/master Commit: 3db2d953b08328d366d10756dbe49874ec8041d5 Parents: a255f68 Author: Rami Alia <[email protected]> Authored: Mon Apr 25 13:42:52 2016 -0400 Committer: Glynn Bird <[email protected]> Committed: Wed Oct 26 14:37:28 2016 +0100 ---------------------------------------------------------------------- lib/nano.js | 18 ++++++++++++------ tests/integration/document/destroy.js | 8 ++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/3db2d953/lib/nano.js ---------------------------------------------------------------------- diff --git a/lib/nano.js b/lib/nano.js index 79ea56e..440cdde 100644 --- a/lib/nano.js +++ b/lib/nano.js @@ -396,12 +396,18 @@ module.exports = exports = nano = function dbScope(cfg) { // http://docs.couchdb.org/en/latest/api/document/common.html#delete--db-docid function destroyDoc(docName, rev, callback) { - return relax({ - db: dbName, - doc: docName, - method: 'DELETE', - qs: {rev: rev} - }, callback); + if(!docName) { + if(callback) + callback("Invalid doc id", null); + } + else { + return relax({ + db: dbName, + doc: docName, + method: 'DELETE', + qs: {rev: rev} + }, callback); + } } // http://docs.couchdb.org/en/latest/api/document/common.html#get--db-docid http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/3db2d953/tests/integration/document/destroy.js ---------------------------------------------------------------------- diff --git a/tests/integration/document/destroy.js b/tests/integration/document/destroy.js index 0d6bdf7..7e07448 100644 --- a/tests/integration/document/destroy.js +++ b/tests/integration/document/destroy.js @@ -29,6 +29,14 @@ it('should insert a document', function(assert) { }); }); +it('should not delete a db', function(assert) { + db.destroy(undefined, undefined, function(error, response) { + assert.equal(error, 'Invalid doc id', 'validated delete parameters'); + assert.equal(response, null, 'ok!'); + assert.end(); + }); +}); + it('should delete a document', function(assert) { db.destroy('foobaz', rev, function(error, response) { assert.equal(error, null, 'deleted foo');
