You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2012/05/26 21:38:01 UTC
git commit: COUCHDB-1483 - Update handlers must produce valid doc ids
Updated Branches:
refs/heads/master e4d3e15ca -> 72ea7e382
COUCHDB-1483 - Update handlers must produce valid doc ids
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/72ea7e38
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/72ea7e38
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/72ea7e38
Branch: refs/heads/master
Commit: 72ea7e382b22074733a3faa9906864ed78f70bf0
Parents: e4d3e15
Author: Robert Newson <rn...@apache.org>
Authored: Sat May 26 20:36:11 2012 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Sat May 26 20:36:11 2012 +0100
----------------------------------------------------------------------
share/www/script/test/update_documents.js | 11 ++++++++++-
src/couch_mrview/src/couch_mrview_show.erl | 1 +
src/couchdb/couch_doc.erl | 2 ++
3 files changed, 13 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/72ea7e38/share/www/script/test/update_documents.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/update_documents.js b/share/www/script/test/update_documents.js
index b352bb4..bbaa07d 100644
--- a/share/www/script/test/update_documents.js
+++ b/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);
+
};
http://git-wip-us.apache.org/repos/asf/couchdb/blob/72ea7e38/src/couch_mrview/src/couch_mrview_show.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/src/couch_mrview_show.erl b/src/couch_mrview/src/couch_mrview_show.erl
index 5a7ce5f..426b431 100644
--- a/src/couch_mrview/src/couch_mrview_show.erl
+++ b/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),
{[
http://git-wip-us.apache.org/repos/asf/couchdb/blob/72ea7e38/src/couchdb/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl
index b565a91..349df4a 100644
--- a/src/couchdb/couch_doc.erl
+++ b/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">>});