couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r735850 - in /couchdb/trunk: share/www/script/couch_tests.js src/couchdb/couch_httpd.erl src/couchdb/couch_httpd_db.erl
Date Mon, 19 Jan 2009 22:22:38 GMT
Author: jchris
Date: Mon Jan 19 14:22:37 2009
New Revision: 735850

URL: http://svn.apache.org/viewvc?rev=735850&view=rev
Log:
fix for COUCHDB-214 (design docs on dbs with slashes)

Modified:
    couchdb/trunk/share/www/script/couch_tests.js
    couchdb/trunk/src/couchdb/couch_httpd.erl
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=735850&r1=735849&r2=735850&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Mon Jan 19 14:22:37 2009
@@ -1235,60 +1235,64 @@
   },
 
   design_paths : function(debug) {
-    var db = new CouchDB("test_suite_db");
-    db.deleteDb();
-    db.createDb();
     if (debug) debugger;
-    
-    // create a ddoc w bulk_docs
-    db.bulkSave([{
-      _id : "_design/test",
-      views : {
-        "testing" : {
-          "map" : "function(){emit(1,1)}"
-        }
-      }
-    }])
-    
-    // ddoc is getable
-    var xhr = CouchDB.request("GET", "/test_suite_db/_design/test");
-    var resp = JSON.parse(xhr.responseText);
-    T(resp._id == "_design/test");
-    
-    // it's at 2 urls...
-    var xhr = CouchDB.request("GET", "/test_suite_db/_design%2Ftest");
-    var resp = JSON.parse(xhr.responseText);
-    T(resp._id == "_design/test");
-    
-    // ensure that views are addressable
-    resp = db.view("test/testing")
-    T(resp.total_rows == 0)
-    
-    // create a ddoc by putting to url with raw slash
-    var xhr = CouchDB.request("PUT", "/test_suite_db/_design/test2",{
-      body : JSON.stringify({
-        _id : "_design/test2",
+    var dbNames = ["test_suite_db", "test_suite_db/with_slashes"];
+    for (var i=0; i < dbNames.length; i++) {
+      var db = new CouchDB(dbNames[i]);
+      var dbName = encodeURIComponent(dbNames[i]);
+      db.deleteDb();
+      db.createDb();
+      
+      // create a ddoc w bulk_docs
+      db.bulkSave([{
+        _id : "_design/test",
         views : {
           "testing" : {
             "map" : "function(){emit(1,1)}"
           }
         }
-      })
-    });
-    
-    // ddoc is getable
-    var xhr = CouchDB.request("GET", "/test_suite_db/_design/test2");
-    var resp = JSON.parse(xhr.responseText);
-    T(resp._id == "_design/test2");
-    
-    // it's at 2 urls...
-    var xhr = CouchDB.request("GET", "/test_suite_db/_design%2Ftest2");
-    var resp = JSON.parse(xhr.responseText);
-    T(resp._id == "_design/test2");
-    
-    // ensure that views are addressable
-    resp = db.view("test2/testing")
-    T(resp.total_rows == 0)
+      }]);
+
+      // ddoc is getable
+      var xhr = CouchDB.request("GET", "/"+dbName+"/_design/test");
+      var resp = JSON.parse(xhr.responseText);
+      T(resp._id == "_design/test");
+
+      // it's at 2 urls...
+      var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Ftest");
+      var resp = JSON.parse(xhr.responseText);
+      T(resp._id == "_design/test");
+
+      // ensure that views are addressable
+      resp = db.view("test/testing")
+      T(resp.total_rows == 0)
+
+      // create a ddoc by putting to url with raw slash
+      var xhr = CouchDB.request("PUT", "/"+dbName+"/_design/test2",{
+        body : JSON.stringify({
+          _id : "_design/test2",
+          views : {
+            "testing" : {
+              "map" : "function(){emit(1,1)}"
+            }
+          }
+        })
+      });
+
+      // ddoc is getable
+      var xhr = CouchDB.request("GET", "/"+dbName+"/_design/test2");
+      var resp = JSON.parse(xhr.responseText);
+      T(resp._id == "_design/test2");
+
+      // it's at 2 urls...
+      var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Ftest2");
+      var resp = JSON.parse(xhr.responseText);
+      T(resp._id == "_design/test2");
+
+      // ensure that views are addressable
+      resp = db.view("test2/testing");
+      T(resp.total_rows == 0);
+    };
   },
 
   content_negotiation: function(debug) {

Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=735850&r1=735849&r2=735850&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Mon Jan 19 14:22:37 2009
@@ -16,7 +16,7 @@
 -export([start_link/0, stop/0, handle_request/3]).
 
 -export([header_value/2,header_value/3,qs_value/2,qs_value/3,qs/1,path/1]).
--export([verify_is_server_admin/1,unquote/1,recv/2]).
+-export([verify_is_server_admin/1,unquote/1,quote/1,recv/2]).
 -export([parse_form/1,json_body/1,body/1,doc_etag/1]).
 -export([primary_header_value/2,partition/1,serve_file/3]).
 -export([start_chunked_response/3,send_chunk/2]).
@@ -152,7 +152,9 @@
     try
         HandlerFun(HttpReq#httpd{user_ctx=AuthenticationFun(HttpReq)})
     catch
-        _Tag:Error ->
+        Tag:Error ->
+            ?LOG_ERROR("Uncaught error in HTTP request: ~p",[{Tag, Error}]),
+            ?LOG_DEBUG("Stacktrace: ~p",[erlang:get_stacktrace()]),
             send_error(HttpReq, Error)
     end,
 
@@ -241,6 +243,9 @@
 unquote(UrlEncodedString) ->
     mochiweb_util:unquote(UrlEncodedString).
 
+quote(UrlDecodedString) ->
+    mochiweb_util:quote_plus(UrlDecodedString).
+
 parse_form(#httpd{mochi_req=MochiReq}) ->
     mochiweb_multipart:parse_form(MochiReq).
 

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=735850&r1=735849&r2=735850&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Mon Jan 19 14:22:37 2009
@@ -256,9 +256,10 @@
 % Special case to enable using an unencoded slash in the URL of design docs, 
 % as slashes in document IDs must otherwise be URL encoded.
 db_req(#httpd{method='GET',mochi_req=MochiReq, path_parts=[DbName,<<"_design/",_/binary>>|_]}=Req,
_Db) ->
-    PathFront = "/" ++ binary_to_list(DbName) ++ "/_design",
-    {ok, [PathFront|PathTail]} = regexp:split(MochiReq:get(raw_path),"%2F"),
-    RedirectTo = PathFront ++ "/" ++ mochiweb_util:join(PathTail, "%2F"),
+    PathFront = "/" ++ couch_httpd:quote(binary_to_list(DbName)) ++ "/",
+    RawSplit = regexp:split(MochiReq:get(raw_path),"_design%2F"),
+    {ok, [PathFront|PathTail]} = RawSplit,
+    RedirectTo = PathFront ++ "_design/" ++ mochiweb_util:join(PathTail, "%2F"),
     couch_httpd:send_response(Req, 301, [{"Location", RedirectTo}], <<>>);
 
 db_req(#httpd{path_parts=[_DbName,<<"_design">>,Name]}=Req, Db) ->



Mime
View raw message