diff options
author | Jan Lehnardt <jan@apache.org> | 2009-11-05 12:19:51 +0000 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2009-11-05 12:19:51 +0000 |
commit | ac2900a560c2c4288c4d91622cf3fd6db4959819 (patch) | |
tree | e79beb00ba8020b6d6945a2db1c151e9ad2b5e6e | |
parent | 198073d4717244773c6f612b496887bbab823356 (diff) |
add safety net for code accidents where the document id in a doc delete request got missing accidentally
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@833036 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | share/www/script/test/basics.js | 7 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 9 |
2 files changed, 15 insertions, 1 deletions
diff --git a/share/www/script/test/basics.js b/share/www/script/test/basics.js index a261b5ae..7e0fe0d6 100644 --- a/share/www/script/test/basics.js +++ b/share/www/script/test/basics.js @@ -235,4 +235,11 @@ couchTests.basics = function(debug) { result = JSON.parse(xhr.responseText); T(result.error == "bad_request"); T(result.reason == "`keys` member must be a array."); + + // oops, the doc id got lost in code nirwana + xhr = CouchDB.request("DELETE", "/test_suite_db/?rev=foobarbaz"); + TEquals(400, xhr.status, "should return a bad request"); + result = JSON.parse(xhr.responseText); + TEquals("bad_request", result.error); + TEquals("You tried to DELETE a database with a ?=rev parameter. Did mean to DELETE a document instead?", result.reason); }; diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index f7fd24a8..3e33bd79 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -39,7 +39,14 @@ handle_request(#httpd{path_parts=[DbName|RestParts],method=Method, {'PUT', []} -> create_db_req(Req, DbName); {'DELETE', []} -> - delete_db_req(Req, DbName); + % if we get ?rev=... the user is using a faulty script where the + % document id is empty by accident. Let them recover safely. + case couch_httpd:qs_value(Req, "rev", false) of + false -> delete_db_req(Req, DbName); + _Rev -> throw({bad_request, + "You tried to DELETE a database with a ?=rev parameter. " + ++ "Did mean to DELETE a document instead?"}) + end; {_, []} -> do_db_req(Req, fun db_req/2); {_, [SecondPart|_]} -> |