summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2011-09-13 18:54:31 +0000
committerJan Lehnardt <jan@apache.org>2011-09-13 18:54:31 +0000
commit9d93a3ee880bc1a64e9c3e6141c517ed4295661c (patch)
tree28668fa1120e5789f68c52d983cd949afecce8ad
parentfb94d04c2dd4a9b39f1e961d4509bf07b07834ef (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--THANKS1
-rw-r--r--share/www/script/test/update_documents.js14
-rw-r--r--src/couchdb/couch_httpd_show.erl8
3 files changed, 20 insertions, 3 deletions
diff --git a/THANKS b/THANKS
index 3aee0fb9..76a0c19b 100644
--- a/THANKS
+++ b/THANKS
@@ -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]