| a | b | |
|---|
| 0 | + | diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl |
|---|
| 0 | + | index 6c3d0e3..5fb0bee 100644 |
|---|
| 0 | + | --- a/src/couchdb/couch_httpd_rewrite.erl |
|---|
| 0 | + | +++ b/src/couchdb/couch_httpd_rewrite.erl |
|---|
| 0 | + | @@ -236,46 +236,20 @@ make_query_list([{Key, {Value}}|Rest], Bindings, Acc) -> |
|---|
| 0 | + | Value1 = to_json({Value}), |
|---|
| 0 | + | make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]); |
|---|
| 0 | + | make_query_list([{Key, Value}|Rest], Bindings, Acc) when is_binary(Value) -> |
|---|
| 0 | + | - Value1 = replace_var(Key, Value, Bindings), |
|---|
| 0 | + | + Value1 = replace_var(Value, Bindings), |
|---|
| 0 | + | make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]); |
|---|
| 0 | + | make_query_list([{Key, Value}|Rest], Bindings, Acc) when is_list(Value) -> |
|---|
| 0 | + | - Value1 = replace_var(Key, Value, Bindings), |
|---|
| 0 | + | + Value1 = to_json([replace_var(V, Bindings) || V <- Value]), |
|---|
| 0 | + | make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]); |
|---|
| 0 | + | make_query_list([{Key, Value}|Rest], Bindings, Acc) -> |
|---|
| 0 | + | make_query_list(Rest, Bindings, [{to_binding(Key), Value}|Acc]). |
|---|
| 0 | + | |
|---|
| 0 | + | -replace_var(Key, Value, Bindings) -> |
|---|
| 0 | + | - case Value of |
|---|
| 0 | + | - <<":", Var/binary>> -> |
|---|
| 0 | + | - get_var(Var, Bindings, Value); |
|---|
| 0 | + | - _ when is_list(Value) -> |
|---|
| 0 | + | - Value1 = lists:foldr(fun(V, Acc) -> |
|---|
| 0 | + | - V1 = case V of |
|---|
| 0 | + | - <<":", VName/binary>> -> |
|---|
| 0 | + | - case get_var(VName, Bindings, V) of |
|---|
| 0 | + | - V2 when is_list(V2) -> |
|---|
| 0 | + | - iolist_to_binary(V2); |
|---|
| 0 | + | - V2 -> V2 |
|---|
| 0 | + | - end; |
|---|
| 0 | + | - _ -> |
|---|
| 0 | + | - |
|---|
| 0 | + | - V |
|---|
| 0 | + | - end, |
|---|
| 0 | + | - [V1|Acc] |
|---|
| 0 | + | - end, [], Value), |
|---|
| 0 | + | - to_json(Value1); |
|---|
| 0 | + | - _ when is_binary(Value) -> |
|---|
| 0 | + | - Value; |
|---|
| 0 | + | - _ -> |
|---|
| 0 | + | - case Key of |
|---|
| 0 | + | - <<"key">> -> to_json(Value); |
|---|
| 0 | + | - <<"startkey">> -> to_json(Value); |
|---|
| 0 | + | - <<"endkey">> -> to_json(Value); |
|---|
| 0 | + | - _ -> |
|---|
| 0 | + | - lists:flatten(?JSON_ENCODE(Value)) |
|---|
| 0 | + | - end |
|---|
| 0 | + | - end. |
|---|
| 0 | + | - |
|---|
| 0 | + | +replace_var(<<":", Var/binary>> = Value, Bindings) -> |
|---|
| 0 | + | + get_var(Var, Bindings, Value); |
|---|
| 0 | + | +replace_var(Value, _Bindings) when is_binary(Value) -> |
|---|
| 0 | + | + Value; |
|---|
| 0 | + | +replace_var(Value, _Bindings) -> |
|---|
| 0 | + | + to_json(Value). |
|---|
| 0 | + | |
|---|
| 0 | + | get_var(VarName, Props, Default) -> |
|---|
| 0 | + | VarName1 = to_binding(VarName), |
|---|
| ... | |
|---|