diff options
-rw-r--r-- | share/www/script/test/copy_doc.js | 3 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 22 |
2 files changed, 16 insertions, 9 deletions
diff --git a/share/www/script/test/copy_doc.js b/share/www/script/test/copy_doc.js index a6de1892..99e3c7fe 100644 --- a/share/www/script/test/copy_doc.js +++ b/share/www/script/test/copy_doc.js @@ -36,6 +36,9 @@ couchTests.copy_doc = function(debug) { }); T(xhr.status == 409); // conflict + var xhr = CouchDB.request("COPY", "/test_suite_db/doc_to_be_copied2"); + T(xhr.status == 400); // bad request (no Destination header) + 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..51c9ae9a 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -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 in 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) -> |