You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2009/02/13 19:33:17 UTC

svn commit: r744210 - in /couchdb/trunk: share/www/script/couch_tests.js src/couchdb/couch_httpd_show.erl src/couchdb/couch_httpd_view.erl

Author: jchris
Date: Fri Feb 13 18:33:16 2009
New Revision: 744210

URL: http://svn.apache.org/viewvc?rev=744210&view=rev
Log:
Apply COUCHDB-251. 
Allow _list functions to accept arbitrary GET parameters.
Thanks Paul Davis.

Modified:
    couchdb/trunk/share/www/script/couch_tests.js
    couchdb/trunk/src/couchdb/couch_httpd_show.erl
    couchdb/trunk/src/couchdb/couch_httpd_view.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=744210&r1=744209&r2=744210&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Fri Feb 13 18:33:16 2009
@@ -2795,6 +2795,10 @@
               }
             }
           })
+        }),
+        qsParams: stringFun(function(head, row, req, row_number) {
+          if(head) return {body: req.query.foo};
+          else return {body: "\n"};
         })
       }
     };
@@ -2862,6 +2866,10 @@
     T(xhr.getResponseHeader("Content-Type") == "application/xml");
     T(xhr.responseText.match(/XML/));
     T(xhr.responseText.match(/entry/));
+
+    // now with extra qs params
+    xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/qsParams/basicView?foo=blam");
+    T(xhr.responseText.match(/blam/));
   },
 
   compact: function(debug) {

Modified: couchdb/trunk/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_show.erl?rev=744210&r1=744209&r2=744210&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_show.erl Fri Feb 13 18:33:16 2009
@@ -75,7 +75,7 @@
     #view_query_args{
         stale = Stale,
         reduce = Reduce
-    } = QueryArgs = couch_httpd_view:parse_view_query(Req),
+    } = QueryArgs = couch_httpd_view:parse_view_query(Req, nil, nil, true),
     case couch_view:get_map_view(Db, DesignId, ViewName, Stale) of
     {ok, View} ->    
         output_map_list(Req, Lang, ListSrc, View, Db, QueryArgs);

Modified: couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=744210&r1=744209&r2=744210&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_view.erl Fri Feb 13 18:33:16 2009
@@ -15,7 +15,7 @@
 
 -export([handle_view_req/2,handle_temp_view_req/2]).
 
--export([parse_view_query/1,parse_view_query/2,make_view_fold_fun/5,
+-export([parse_view_query/1,parse_view_query/2,parse_view_query/4,make_view_fold_fun/5,
     finish_view_fold/3, view_row_obj/3]).
 
 -import(couch_httpd,
@@ -210,6 +210,8 @@
 parse_view_query(Req, Keys) ->
     parse_view_query(Req, Keys, nil).
 parse_view_query(Req, Keys, IsReduce) ->
+    parse_view_query(Req, Keys, IsReduce, false).
+parse_view_query(Req, Keys, IsReduce, IgnoreExtra) ->
     QueryList = couch_httpd:qs(Req),
     #view_query_args{
         group_level = GroupLevel
@@ -332,9 +334,14 @@
             % we just ignore format, so that JS can have it
             Args;
         _ -> % unknown key
-            Msg = lists:flatten(io_lib:format(
-                "Bad URL query key:~s", [Key])),
-            throw({query_parse_error, Msg})
+            case IgnoreExtra of
+            true ->
+                Args;
+            false ->
+                Msg = lists:flatten(io_lib:format(
+                    "Bad URL query key:~s", [Key])),
+                throw({query_parse_error, Msg})
+            end
         end
     end, #view_query_args{}, QueryList),
     case IsReduce of