Skip to content
Browse files

COUCHDB-1483 - Update handlers must produce valid doc ids

  • Loading branch information...
1 parent e4d3e15 commit 72ea7e382b22074733a3faa9906864ed78f70bf0 @rnewson rnewson committed May 26, 2012
View
11 share/www/script/test/update_documents.js
@@ -95,7 +95,10 @@ couchTests.update_documents = function(debug) {
"base64" : "aGVsbG8gd29ybGQh" // "hello world!" encoded
};
return [doc, resp];
- })
+ }),
+ "empty" : stringFun(function(doc, req) {
+ return [{}, 'oops'];
+ })
}
};
T(db.save(designDoc).ok);
@@ -221,4 +224,10 @@ couchTests.update_documents = function(debug) {
T(xhr.status == 201);
T(xhr.responseText == "hello world!");
T(/application\/octet-stream/.test(xhr.getResponseHeader("Content-Type")));
+
+ // Insert doc with empty id
+ xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/empty/foo");
+ TEquals(400, xhr.status);
+ TEquals("Document id must not be empty", JSON.parse(xhr.responseText).reason);
+
};
View
1 src/couch_mrview/src/couch_mrview_show.erl
@@ -141,6 +141,7 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
Options = [{user_ctx, Req#httpd.user_ctx}]
end,
NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
+ couch_doc:validate_docid(NewDoc#doc.id),
{ok, NewRev} = couch_db:update_doc(Db, NewDoc, Options),
NewRevStr = couch_doc:rev_to_str(NewRev),
{[
View
2 src/couchdb/couch_doc.erl
@@ -188,6 +188,8 @@ parse_revs([Rev | Rest]) ->
[parse_rev(Rev) | parse_revs(Rest)].
+validate_docid(<<"">>) ->
+ throw({bad_request, <<"Document id must not be empty">>});
validate_docid(Id) when is_binary(Id) ->
case couch_util:validate_utf8(Id) of
false -> throw({bad_request, <<"Document id must be valid UTF-8">>});

0 comments on commit 72ea7e3

Please sign in to comment.
Something went wrong with that request. Please try again.