You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/06/26 06:55:54 UTC
[GitHub] glynnbird closed pull request #78: Return error if nano.db.get
called with empty doc name (Fixes issue #70)
glynnbird closed pull request #78: Return error if nano.db.get called with empty doc name (Fixes issue #70)
URL: https://github.com/apache/couchdb-nano/pull/78
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/lib/nano.js b/lib/nano.js
index 02c04e1..08a5479 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -456,7 +456,13 @@ module.exports = exports = nano = function dbScope(cfg) {
qs = {};
}
- return relax({db: dbName, doc: docName, qs: qs}, callback);
+ if(!docName) {
+ if(callback)
+ callback("Invalid doc id", null);
+ }
+ else {
+ return relax({db: dbName, doc: docName, qs: qs}, callback);
+ }
}
// http://docs.couchdb.org/en/latest/api/document/common.html#head--db-docid
diff --git a/tests/unit/document/get.js b/tests/unit/document/get.js
new file mode 100644
index 0000000..bbe18b7
--- /dev/null
+++ b/tests/unit/document/get.js
@@ -0,0 +1,41 @@
+// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+'use strict';
+
+var helpers = require('../../helpers/unit');
+var test = require('tape');
+var debug = require('debug')('nano/tests/unit/shared/error');
+
+var cli = helpers.mockClientDb(debug)
+var db = cli.use('foo')
+
+test('it should not return db info if docName undefined', function(assert) {
+ db.get(undefined, function(err) {
+ assert.equal(err, 'Invalid doc id');
+ assert.end();
+ });
+});
+
+test('it should not return db info if docName null', function(assert) {
+ db.get(null, function(err) {
+ assert.equal(err, 'Invalid doc id');
+ assert.end();
+ });
+});
+
+test('it should not return db info if docName empty string', function(assert) {
+ db.get('', function(err) {
+ assert.equal(err, 'Invalid doc id');
+ assert.end();
+ });
+});
\ No newline at end of file
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services