summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/www/script/couch.js2
-rw-r--r--share/www/script/test/copy_doc.js5
-rw-r--r--src/couchdb/couch_httpd_db.erl24
3 files changed, 20 insertions, 11 deletions
diff --git a/share/www/script/couch.js b/share/www/script/couch.js
index 913f58fb..633abe96 100644
--- a/share/www/script/couch.js
+++ b/share/www/script/couch.js
@@ -121,7 +121,7 @@ function CouchDB(name, httpHeaders) {
CouchDB.maybeThrowError(this.last_req);
var results = JSON.parse(this.last_req.responseText);
for (var i = 0; i < docs.length; i++) {
- if(results[i] && results[i].rev) {
+ if(results[i] && results[i].rev && results[i].ok) {
docs[i]._rev = results[i].rev;
}
}
diff --git a/share/www/script/test/copy_doc.js b/share/www/script/test/copy_doc.js
index a6de1892..a15e3ef8 100644
--- a/share/www/script/test/copy_doc.js
+++ b/share/www/script/test/copy_doc.js
@@ -23,6 +23,7 @@ couchTests.copy_doc = function(debug) {
});
T(xhr.status == 201);
+ T(JSON.parse(xhr.responseText).ok);
T(db.open("doc_that_was_copied").v == 1);
// COPY with existing target
@@ -36,6 +37,10 @@ couchTests.copy_doc = function(debug) {
});
T(xhr.status == 409); // conflict
+ // missing Destination header
+ var xhr = CouchDB.request("COPY", "/test_suite_db/doc_to_be_copied2");
+ T(xhr.status == 400); // bad request
+
var rev = db.open("doc_to_be_overwritten")._rev;
var xhr = CouchDB.request("COPY", "/test_suite_db/doc_to_be_copied2", {
headers: {"Destination":"doc_to_be_overwritten?rev=" + rev}
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index 93e93892..87cf7265 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -809,7 +809,7 @@ update_doc_result_to_json({{Id, Rev}, Error}) ->
update_doc_result_to_json(#doc{id=DocId}, Result) ->
update_doc_result_to_json(DocId, Result);
update_doc_result_to_json(DocId, {ok, NewRev}) ->
- {[{id, DocId}, {rev, couch_doc:rev_to_str(NewRev)}]};
+ {[{ok, true}, {id, DocId}, {rev, couch_doc:rev_to_str(NewRev)}]};
update_doc_result_to_json(DocId, Error) ->
{_Code, ErrorStr, Reason} = couch_httpd:error_info(Error),
{[{id, DocId}, {error, ErrorStr}, {reason, Reason}]}.
@@ -1216,15 +1216,19 @@ extract_header_rev(Req, ExplicitRev) ->
parse_copy_destination_header(Req) ->
- Destination = couch_httpd:header_value(Req, "Destination"),
- case re:run(Destination, "\\?", [{capture, none}]) of
- nomatch ->
- {list_to_binary(Destination), {0, []}};
- match ->
- [DocId, RevQs] = re:split(Destination, "\\?", [{return, list}]),
- [_RevQueryKey, Rev] = re:split(RevQs, "=", [{return, list}]),
- {Pos, RevId} = couch_doc:parse_rev(Rev),
- {list_to_binary(DocId), {Pos, [RevId]}}
+ case couch_httpd:header_value(Req, "Destination") of
+ undefined ->
+ throw({bad_request, "Destination header is mandatory for COPY"});
+ Destination ->
+ case re:run(Destination, "\\?", [{capture, none}]) of
+ nomatch ->
+ {list_to_binary(Destination), {0, []}};
+ match ->
+ [DocId, RevQs] = re:split(Destination, "\\?", [{return, list}]),
+ [_RevQueryKey, Rev] = re:split(RevQs, "=", [{return, list}]),
+ {Pos, RevId} = couch_doc:parse_rev(Rev),
+ {list_to_binary(DocId), {Pos, [RevId]}}
+ end
end.
validate_attachment_names(Doc) ->