couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1143975 - in /couchdb/trunk: share/www/script/test/copy_doc.js src/couchdb/couch_httpd_db.erl
Date Thu, 07 Jul 2011 18:59:04 GMT
Author: jan
Date: Thu Jul  7 18:59:04 2011
New Revision: 1143975

URL: http://svn.apache.org/viewvc?rev=1143975&view=rev
Log:
Add error response for absolute Destination headers with COPY reuqests.

Modified:
    couchdb/trunk/share/www/script/test/copy_doc.js
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/share/www/script/test/copy_doc.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/copy_doc.js?rev=1143975&r1=1143974&r2=1143975&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/copy_doc.js (original)
+++ couchdb/trunk/share/www/script/test/copy_doc.js Thu Jul  7 18:59:04 2011
@@ -40,6 +40,16 @@ couchTests.copy_doc = function(debug) {
 
   var xhr = CouchDB.request("COPY", "/test_suite_db/doc_to_be_copied2");
   T(xhr.status == 400); // bad request (no Destination header)
+  TEquals("Destination header is mandatory for COPY.", JSON.parse(xhr.responseText).reason,
+    "should report missing destination header");
+
+  var xhr = CouchDB.request("COPY", "/test_suite_db/doc_to_be_copied2", {
+    headers: {
+      "Destination": "http://localhost:5984/test_suite_db/doc_to_be_written"
+  }});
+  TEquals(400, xhr.status, "should throw a 400 error"); // bad request (invalid destination
header)
+  TEquals("Destination URL must be relative.", JSON.parse(xhr.responseText).reason,
+    "should report invalid destination header");
 
   var rev = db.open("doc_to_be_overwritten")._rev;
   var xhr = CouchDB.request("COPY", "/test_suite_db/doc_to_be_copied2", {

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=1143975&r1=1143974&r2=1143975&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Thu Jul  7 18:59:04 2011
@@ -1285,16 +1285,22 @@ extract_header_rev(Req, ExplicitRev) ->
 parse_copy_destination_header(Req) ->
     case couch_httpd:header_value(Req, "Destination") of
         undefined ->
-            throw({bad_request, "Destination header in mandatory for COPY."});
+            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]}}
+            case Destination of
+                "http://" ++ _Rest ->
+                    throw({bad_request, "Destination URL must be relative."});
+                _Else ->
+                % see if ?rev=revid got appended to the Destination header
+                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
     end.
 



Mime
View raw message