rnewson commented on code in PR #4494:
URL: https://github.com/apache/couchdb/pull/4494#discussion_r1156249721


##########
src/couch_mrview/src/couch_mrview_http.erl:
##########
@@ -513,8 +518,22 @@ parse_body_and_query(Req, Keys) ->
 
 parse_body_and_query(Req, {Props}, Keys) ->
     Args = #mrargs{keys = Keys, group = undefined, group_level = undefined},
-    BodyArgs = parse_params(Props, Keys, Args, [decoded]),
-    parse_params(chttpd:qs(Req), Keys, BodyArgs, [keep_group_level]).
+    BodyArgs0 = parse_params(Props, Keys, Args, [decoded]),
+    BodyArgs1 =
+        case is_view(Req) of
+            true -> treat_single_keys_as_key(BodyArgs0);
+            false -> BodyArgs0
+        end,
+    parse_params(chttpd:qs(Req), Keys, BodyArgs1, [keep_group_level]).
+
+is_view(#httpd{path_parts = Path}) ->

Review Comment:
   If you look at chttpd.erl / chttp_view.erl etc you'll see many examples 
where we match on `path_parts` in the function head. It's a very widely used 
pattern and I think we should continue it here. I also note that the 
lists:member function call is not needed in your version, as the lists:nth is 
sufficient.
   
   ```is_view(#httpd{path_paths = [_, _, _, <<"_view">> | _]}) ->
       true;
   is_view(#httpd{}) ->
       false.
   ```



##########
src/couch_mrview/src/couch_mrview_http.erl:
##########
@@ -513,8 +518,22 @@ parse_body_and_query(Req, Keys) ->
 
 parse_body_and_query(Req, {Props}, Keys) ->
     Args = #mrargs{keys = Keys, group = undefined, group_level = undefined},
-    BodyArgs = parse_params(Props, Keys, Args, [decoded]),
-    parse_params(chttpd:qs(Req), Keys, BodyArgs, [keep_group_level]).
+    BodyArgs0 = parse_params(Props, Keys, Args, [decoded]),
+    BodyArgs1 =
+        case is_view(Req) of
+            true -> treat_single_keys_as_key(BodyArgs0);
+            false -> BodyArgs0
+        end,
+    parse_params(chttpd:qs(Req), Keys, BodyArgs1, [keep_group_level]).
+
+is_view(#httpd{path_parts = Path}) ->

Review Comment:
   If you look at chttpd.erl / chttp_view.erl etc you'll see many examples 
where we match on `path_parts` in the function head. It's a very widely used 
pattern and I think we should continue it here. I also note that the 
lists:member function call is not needed in your version, as the lists:nth is 
sufficient.
   
   ```
   is_view(#httpd{path_paths = [_, _, _, <<"_view">> | _]}) ->
       true;
   is_view(#httpd{}) ->
       false.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to