diff options
author | Jan Lehnardt <jan@apache.org> | 2011-09-13 18:54:31 +0000 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2011-09-13 18:54:31 +0000 |
commit | 9d93a3ee880bc1a64e9c3e6141c517ed4295661c (patch) | |
tree | 28668fa1120e5789f68c52d983cd949afecce8ad | |
parent | fb94d04c2dd4a9b39f1e961d4509bf07b07834ef (diff) |
Allow slashes in doc ids in URLs to _update handlers.
This mirrors the behaviour of the _show API.
Patch by Christopher Bonhage.
Closes COUCHDB-1229
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1170299 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | share/www/script/test/update_documents.js | 14 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_show.erl | 8 |
3 files changed, 20 insertions, 3 deletions
@@ -81,5 +81,6 @@ suggesting improvements or submitting changes. Some of these people are: * Nathan Vander Wilt <natevw@yahoo.com> * Caolan McMahon <caolan.mcmahon@googlemail.com> * Alexander Shorin <kxepal@gmail.com> + * Christopher Bonhage <queezey@me.com> For a list of authors see the `AUTHORS` file. diff --git a/share/www/script/test/update_documents.js b/share/www/script/test/update_documents.js index 49d3b68a..4d2b29fc 100644 --- a/share/www/script/test/update_documents.js +++ b/share/www/script/test/update_documents.js @@ -165,4 +165,18 @@ couchTests.update_documents = function(debug) { T(xhr.status == 200); T(xhr.responseText.length == 32); + // COUCHDB-1229 - allow slashes in doc ids for update handlers + // /db/_design/doc/_update/handler/doc/id + + var doc = { + _id:"with/slash", + counter:1 + }; + db.save(doc); + xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/bump-counter/with/slash"); + TEquals(201, xhr.status, "should return a 200 status"); + TEquals("<h1>bumped it!</h1>", xhr.responseText, "should report bumping"); + + var doc = db.open("with/slash"); + TEquals(2, doc.counter, "counter should be 2"); }; diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl index a215b1da..742b0f20 100644 --- a/src/couchdb/couch_httpd_show.erl +++ b/src/couchdb/couch_httpd_show.erl @@ -106,13 +106,15 @@ get_fun_key(DDoc, Type, Name) -> % send_method_not_allowed(Req, "POST,PUT,DELETE,ETC"); handle_doc_update_req(#httpd{ - path_parts=[_, _, _, _, UpdateName, DocId] + path_parts=[_, _, _, _, UpdateName, DocId|Rest] }=Req, Db, DDoc) -> - Doc = try couch_httpd_db:couch_doc_open(Db, DocId, nil, [conflicts]) + DocParts = [DocId|Rest], + DocId1 = ?l2b(string:join([?b2l(P)|| P <- DocParts], "/")), + Doc = try couch_httpd_db:couch_doc_open(Db, DocId1, nil, [conflicts]) catch _ -> nil end, - send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId); + send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId1); handle_doc_update_req(#httpd{ path_parts=[_, _, _, _, UpdateName] |