couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r833036 - in /couchdb/trunk: share/www/script/test/basics.js src/couchdb/couch_httpd_db.erl
Date Thu, 05 Nov 2009 12:20:08 GMT
Author: jan
Date: Thu Nov  5 12:19:51 2009
New Revision: 833036

URL: http://svn.apache.org/viewvc?rev=833036&view=rev
Log:
add safety net for code accidents where the document id in a doc delete request got missing
accidentally

Modified:
    couchdb/trunk/share/www/script/test/basics.js
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/share/www/script/test/basics.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/basics.js?rev=833036&r1=833035&r2=833036&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/basics.js (original)
+++ couchdb/trunk/share/www/script/test/basics.js Thu Nov  5 12:19:51 2009
@@ -235,4 +235,11 @@
   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);
 };

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=833036&r1=833035&r2=833036&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Thu Nov  5 12:19:51 2009
@@ -39,7 +39,14 @@
     {'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|_]} ->



Mime
View raw message