Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 11851 invoked from network); 11 Feb 2009 16:09:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Feb 2009 16:09:00 -0000 Received: (qmail 32262 invoked by uid 500); 11 Feb 2009 16:09:00 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 32238 invoked by uid 500); 11 Feb 2009 16:09:00 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 32229 invoked by uid 99); 11 Feb 2009 16:08:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Feb 2009 08:08:59 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Feb 2009 16:08:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EBF2D238899B; Wed, 11 Feb 2009 16:08:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r743371 - in /couchdb/trunk: share/www/script/couch_tests.js src/couchdb/couch_doc.erl src/couchdb/couch_httpd.erl Date: Wed, 11 Feb 2009 16:08:38 -0000 To: commits@couchdb.apache.org From: damien@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090211160838.EBF2D238899B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: damien Date: Wed Feb 11 16:08:38 2009 New Revision: 743371 URL: http://svn.apache.org/viewvc?rev=743371&view=rev Log: Fix for COUCHDB-238, explicit check and error for doc ids starting with underscore. Modified: couchdb/trunk/share/www/script/couch_tests.js couchdb/trunk/src/couchdb/couch_doc.erl couchdb/trunk/src/couchdb/couch_httpd.erl Modified: couchdb/trunk/share/www/script/couch_tests.js URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=743371&r1=743370&r2=743371&view=diff ============================================================================== --- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original) +++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Wed Feb 11 16:08:38 2009 @@ -1482,6 +1482,49 @@ 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(); Modified: couchdb/trunk/src/couchdb/couch_doc.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_doc.erl?rev=743371&r1=743370&r2=743371&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_doc.erl (original) +++ couchdb/trunk/src/couchdb/couch_doc.erl Wed Feb 11 16:08:38 2009 @@ -112,12 +112,12 @@ <<"conflicts">>, <<"deleted_conflicts">>, <<"deleted">>], % collect all the doc-members that start with "_" % if any aren't in the AllowedSpecialMembers list - % then throw a doc_validation error + % then throw a invalid_doc error [case lists:member(Name, AllowedSpecialMembers) of true -> ok; false -> - throw({doc_validation, io_lib:format("Bad special document member: _~s", [Name])}) + throw({invalid_doc, io_lib:format("Bad special document member: _~s", [Name])}) end || {<<$_,Name/binary>>, _Value} <- Props], Revs = @@ -131,10 +131,14 @@ Revs0 end, case proplists:get_value(<<"_id">>, Props, <<>>) of + <<"_design/", _/binary>> = Id -> ok; + <<"_local/", _/binary>> = Id -> ok; + <<"_", _/binary>> = Id -> + throw({invalid_doc, "Document Ids must not start with underscore."}); Id when is_binary(Id) -> ok; Id -> ?LOG_DEBUG("Document id is not a string: ~p", [Id]), - throw({invalid_document_id, "Document id is not a string"}) + throw({invalid_doc, "Document id is not a string"}) end, % strip out the all props beginning with _ @@ -148,7 +152,7 @@ }; from_json_obj(_Other) -> - throw({invalid_json_object, "Document must be a JSON object"}). + throw({invalid_doc, "Document must be a JSON object"}). to_doc_info(FullDocInfo) -> {DocInfo, _Path} = to_doc_info_path(FullDocInfo), Modified: couchdb/trunk/src/couchdb/couch_httpd.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=743371&r1=743370&r2=743371&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_httpd.erl (original) +++ couchdb/trunk/src/couchdb/couch_httpd.erl Wed Feb 11 16:08:38 2009 @@ -372,6 +372,8 @@ send_error(Req, 404, <<"not_found">>, Reason); send_error(Req, conflict) -> send_error(Req, 409, <<"conflict">>, <<"Document update conflict.">>); +send_error(Req, {invalid_doc, Reason}) -> + send_error(Req, 400, <<"invalid_doc">>, Reason); send_error(Req, {forbidden, Msg}) -> send_json(Req, 403, {[{<<"error">>, <<"forbidden">>},