couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1037194 - in /couchdb/trunk: share/www/script/test/rewrite.js src/couchdb/couch_httpd_rewrite.erl
Date Sat, 20 Nov 2010 12:39:58 GMT
Author: jan
Date: Sat Nov 20 12:39:57 2010
New Revision: 1037194

URL: http://svn.apache.org/viewvc?rev=1037194&view=rev
Log:
Send a user friendly error message when rewrite rules are a String,
not a JSON Array.

Modified:
    couchdb/trunk/share/www/script/test/rewrite.js
    couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl

Modified: couchdb/trunk/share/www/script/test/rewrite.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/rewrite.js?rev=1037194&r1=1037193&r2=1037194&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/rewrite.js (original)
+++ couchdb/trunk/share/www/script/test/rewrite.js Sat Nov 20 12:39:57 2010
@@ -437,7 +437,16 @@ couchTests.rewrite = function(debug) {
               T(result.uuids.length == 1);
               var first = result.uuids[0];
         });
-
   });
-  
+
+  // test invalid rewrites
+  // string
+  var ddoc = {
+    _id: "_design/invalid",
+    rewrites: "[{\"from\":\"foo\",\"to\":\"bar\"}]"
+  }
+  db.save(ddoc);
+  var res = CouchDB.request("GET", "/test_suite_db/_design/invalid/_rewrite/foo");
+  TEquals(400, res.status, "should return 400");
+
 }

Modified: couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl?rev=1037194&r1=1037193&r2=1037194&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl Sat Nov 20 12:39:57 2010
@@ -135,7 +135,10 @@ handle_rewrite_req(#httpd{
     case couch_util:get_value(<<"rewrites">>, Props) of
         undefined ->
             couch_httpd:send_error(Req, 404, <<"rewrite_error">>,
-                            <<"Invalid path.">>);
+                <<"Invalid path.">>);
+        Bin when is_binary(Bin) ->
+            couch_httpd:send_error(Req, 400, <<"rewrite_error">>,
+                <<"Rewrite rules are a String. They must be a JSON Array.">>);
         Rules ->
             % create dispatch list from rules
             DispatchList =  [make_rule(Rule) || {Rule} <- Rules],



Mime
View raw message