From 59f41c2678f59a2effade9651c0de11bbe811c56 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Wed, 11 Feb 2009 16:08:38 +0000 Subject: Fix for COUCHDB-238, explicit check and error for doc ids starting with underscore. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@743371 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_doc.erl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/couchdb/couch_doc.erl') diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl index 5bad7854..1eb1575a 100644 --- a/src/couchdb/couch_doc.erl +++ b/src/couchdb/couch_doc.erl @@ -112,12 +112,12 @@ from_json_obj({Props}) -> <<"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 @@ from_json_obj({Props}) -> 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({Props}) -> }; 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), -- cgit v1.2.3