You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by eiri <gi...@git.apache.org> on 2016/06/13 16:51:31 UTC

[GitHub] couchdb-couch-mrview pull request #48: Allow json_decode in parse_params to ...

GitHub user eiri opened a pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/48

    Allow json_decode in parse_params to be optional

    This allows explicitly indicate if function `parse_params` should decode passed parameter's value instead of trying to guess it by value's term type.
    
    It makes it possible to use this function both with GET and POST queries.
    
    COUCHDB-3031

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/cloudant/couchdb-couch-mrview make-decode-in-parse_params-optional

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/couchdb-couch-mrview/pull/48.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #48
    
----
commit 1738f552e27bea5243130a44ed39eefe15b51a41
Author: Eric Avdey <ei...@eiri.ca>
Date:   2016-06-13T16:28:17Z

    Allow JSON_DECODE in parse_params to be optional
    
    This allows explicitly indicate if parse_params function
    should json decode passed parameters instead of trying
    to guess it by value's term type.
    
    It makes it possible to use this function both with GET
    and POST queries.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview issue #48: Allow json_decode in parse_params to be opti...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson commented on the issue:

    https://github.com/apache/couchdb-couch-mrview/pull/48
  
    +1


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview issue #48: Allow json_decode in parse_params to be opti...

Posted by eiri <gi...@git.apache.org>.
Github user eiri commented on the issue:

    https://github.com/apache/couchdb-couch-mrview/pull/48
  
    @rnewson Changes it to use your suggestion.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview pull request #48: Allow json_decode in parse_params to ...

Posted by rnewson <gi...@git.apache.org>.
Github user rnewson commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch-mrview/pull/48#discussion_r66829121
  
    --- Diff: src/couch_mrview_http.erl ---
    @@ -439,39 +440,43 @@ parse_params(Props, Keys) ->
         parse_params(Props, Keys, Args).
     
     
    -parse_params(Props, Keys, #mrargs{}=Args0) ->
    +parse_params(Props, Keys, Args) ->
    +    parse_params(Props, Keys, Args, []).
    +
    +parse_params(Props, Keys, #mrargs{}=Args0, Options) ->
    +    IsDecoded = lists:member(decoded, Options),
         % group_level set to undefined to detect if explicitly set by user
         Args1 = Args0#mrargs{keys=Keys, group=undefined, group_level=undefined},
         lists:foldl(fun({K, V}, Acc) ->
    -        parse_param(K, V, Acc)
    +        parse_param(K, V, Acc, IsDecoded)
         end, Args1, Props).
     
     
    -parse_param(Key, Val, Args) when is_binary(Key) ->
    -    parse_param(binary_to_list(Key), Val, Args);
    -parse_param(Key, Val, Args) ->
    +parse_param(Key, Val, Args, IsDecoded) when is_binary(Key) ->
    +    parse_param(binary_to_list(Key), Val, Args, IsDecoded);
    +parse_param(Key, Val, Args, IsDecoded) ->
         case Key of
             "" ->
                 Args;
             "reduce" ->
                 Args#mrargs{reduce=parse_boolean(Val)};
             "key" ->
    -            JsonKey = parse_json(Val),
    +            JsonKey = parse_json(Val, IsDecoded),
    --- End diff --
    
    now that we look again, it's odd to have a function called parse_json that conditionally doesn't parse json. How about a clause for each right here?;
    
    -parse_param(Key, Val, Args) when is_binary(Key) ->
    -    parse_param(binary_to_list(Key), Val, Args);
    -parse_param(Key, Val, Args) ->
    +parse_param(Key, Val, Args, IsDecoded) when is_binary(Key) ->
    +    parse_param(binary_to_list(Key), Val, Args, IsDecoded);
    +parse_param(Key, Val, Args, IsDecoded) ->
         case Key of
             "" ->
                 Args;
             "reduce" ->
                 Args#mrargs{reduce=parse_boolean(Val)};
    +        "key" when IsDecoded ->
    +            Args#mrargs{start_key=Val, end_key=Val};
             "key" ->
                 JsonKey = ?JSON_DECODE(Val),
                 Args#mrargs{start_key=JsonKey, end_key=JsonKey};



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview pull request #48: Allow json_decode in parse_params to ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/couchdb-couch-mrview/pull/48


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] couchdb-couch-mrview issue #48: Allow json_decode in parse_params to be opti...

Posted by davisp <gi...@git.apache.org>.
Github user davisp commented on the issue:

    https://github.com/apache/couchdb-couch-mrview/pull/48
  
    +1


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---