From 59f41c2678f59a2effade9651c0de11bbe811c56 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Wed, 11 Feb 2009 16:08:38 +0000 Subject: Fix for COUCHDB-238, explicit check and error for doc ids starting with underscore. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@743371 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch_tests.js | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'share') diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 2df262d7..55a63bc9 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -1482,6 +1482,49 @@ db.createDb(); T(db.view("test/no_docs") == null); }, + invalid_docids: function(debug) { + var db = new CouchDB("test_suite_db"); + db.deleteDb(); + db.createDb(); + if (debug) debugger; + + // Test _local explicitly first. + T(db.save({"_id": "_local/foo"}).ok); + T(db.open("_local/foo")._id == "_local/foo"); + + //Test non-string + try { + db.save({"_id": 1}); + T(1 == 0); + } catch(e) { + T(db.last_req.status == 400); + T(e.error == "invalid_doc"); + } + + // Test invalid _prefix + try { + db.save({"_id": "_invalid"}); + T(1 == 0); + } catch(e) { + T(db.last_req.status == 400); + T(e.error == "invalid_doc"); + } + + // Test _bulk_docs explicitly. + var docs = [{"_id": "_design/foo"}, {"_id": "_local/bar"}]; + T(db.bulkSave(docs).ok); + docs.forEach(function(d) {T(db.open(d._id)._id == d._id);}); + + docs = [{"_id": "_invalid"}]; + try { + db.bulkSave(docs); + T(1 == 0); + } catch(e) { + T(db.last_req.status == 400); + T(e.error == "invalid_doc"); + } + }, + view_collation: function(debug) { var db = new CouchDB("test_suite_db"); db.deleteDb(); -- cgit v1.2.3