On 9 May 2009, at 21:06, [email protected] wrote:

Author: davisp
Date: Sat May  9 19:06:00 2009
New Revision: 773260

URL: http://svn.apache.org/viewvc?rev=773260&view=rev
Log:
Check for invalid document members.

Removes a guard that only checked for fields with integer values. Adds tests to
basics.js


Modified:
   couchdb/trunk/share/www/script/test/basics.js
   couchdb/trunk/src/couchdb/couch_doc.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=773260&r1=773259&r2=773260&view=diff
= = = = = = = = ======================================================================
--- couchdb/trunk/share/www/script/test/basics.js (original)
+++ couchdb/trunk/share/www/script/test/basics.js Sat May 9 19:06:00 2009
@@ -169,6 +169,28 @@
xhr = CouchDB.request("DELETE", "/test_suite_db/doc-does-not- exist");
    T(xhr.status == 404);

+  // Check for invalid document members
+  bad_docs = [
+    ["goldfish", {"_zing": 4}],
+    ["zebrafish", {"_zoom": "hello"}],
+ ["mudfish", {"zane": "goldfish", "_fan": "something smells delicious"}],
+    ["tastyfish", {"_bing": {"wha?": "soda can"}}]
+  ]
+  var test_doc = function(info) {
+    var data = JSON.stringify(info[1]);
+
+ xhr = CouchDB.request("PUT", "/test_suite_db/" + info[0], {body: data});
+    T(xhr.status == 500);

A web server should send a 500 error on purpose. It is meant as a catch-all error condition for unknown and unforeseen errors. Unfortunately there's not a very good fitting 4xx code for this, but the closest would probably be a
400 Bad Request.


Cheers
Jan
--


+    result = JSON.parse(xhr.responseText);
+    T(result.error == "doc_validation");
+
+    xhr = CouchDB.request("POST", "/test_suite_db/", {body: data});
+    T(xhr.status == 500);
+    result = JSON.parse(xhr.responseText);
+    T(result.error == "doc_validation");
+  };
+  bad_docs.forEach(test_doc);
+
    // Check some common error responses.
    // PUT body not an object
    xhr = CouchDB.request("PUT", "/test_suite_db/bar", {body: "[]"});

Modified: couchdb/trunk/src/couchdb/couch_doc.erl
URL: 
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_doc.erl?rev=773260&r1=773259&r2=773260&view=diff
= = = = = = = = ======================================================================
--- couchdb/trunk/src/couchdb/couch_doc.erl (original)
+++ couchdb/trunk/src/couchdb/couch_doc.erl Sat May  9 19:06:00 2009
@@ -215,7 +215,7 @@
    transfer_fields(Rest, Doc);

% unknown special field
-transfer_fields([{<<"_",Name/binary>>, Start} | _], _) when is_integer(Start) ->
+transfer_fields([{<<"_",Name/binary>>, _} | _], _) ->
    throw({doc_validation,
?l2b(io_lib:format("Bad special document member: _~s", [Name]))});





Reply via email to