summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/test/basics.js22
-rw-r--r--src/couchdb/couch_doc.erl2
2 files changed, 23 insertions, 1 deletions
diff --git a/share/www/script/test/basics.js b/share/www/script/test/basics.js
index 2eb49ebe..8e6d4c7a 100644
--- a/share/www/script/test/basics.js
+++ b/share/www/script/test/basics.js
@@ -169,6 +169,28 @@ couchTests.basics = function(debug) {
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);
+ 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: "[]"});
diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl
index 4d2affa4..906a5725 100644
--- a/src/couchdb/couch_doc.erl
+++ b/src/couchdb/couch_doc.erl
@@ -215,7 +215,7 @@ transfer_fields([{<<"_deleted_conflicts">>, _} | Rest], Doc) ->
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]))});