anchor.diff:  
                       % build new path, reencode query args, eventually convert
                       % them to json
  -                    Path = lists:append(
  -                        string:join(Parts, [?SEPARATOR]),
  -                        case Bindings of
  -                            [] -> [];
  -                            _ -> [$?, encode_query(Bindings)]
  -                        end),
  -                    
  +                    Bindings1 = maybe_encode_bindings(Bindings),
  +                    Path = binary_to_list(
  +                        iolist_to_binary([
  +                                string:join(Parts, [?SEPARATOR]),
  +                                [["?", mochiweb_util:urlencode(Bindings1)]
  +                                    || Bindings1 =/= [] ]
  +                            ])),
  +
                       % if path is relative detect it and rewrite path
                       case mochiweb_util:safe_relative_path(Path) of
                           undefined ->
  
positive.code: %% rewriting dynamically the quey list given as query member in
  %% rewrites. Each value is replaced by one binding or an argument
  %% passed in url.
  make_query_list([], _Bindings, Acc) ->
      Acc;
  make_query_list([{Key, {Value}}|Rest], Bindings, Acc) ->
      Value1 = to_json({Value}),
      make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]);
  make_query_list([{Key, Value}|Rest], Bindings, Acc) when is_binary(Value) ->
      Value1 = replace_var(Key, Value, Bindings),
      make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]);
  make_query_list([{Key, Value}|Rest], Bindings, Acc) when is_list(Value) ->
      Value1 = replace_var(Key, Value, Bindings),
      make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]);
  make_query_list([{Key, Value}|Rest], Bindings, Acc) ->
      make_query_list(Rest, Bindings, [{to_binding(Key), Value}|Acc]).
  
  replace_var(Key, Value, Bindings) ->
      case Value of
          <<":", Var/binary>> ->
              get_var(Var, Bindings, Value);
          _ when is_list(Value) ->
              Value1 = lists:foldr(fun(V, Acc) ->
                  V1 = case V of
                      <<":", VName/binary>> ->
                          case get_var(VName, Bindings, V) of
                              V2 when is_list(V2) ->
                                  iolist_to_binary(V2);
                              V2 -> V2
                          end;
                      _ ->
                          
                          V
                  end,
                  [V1|Acc]
              end, [], Value),
              to_json(Value1);
          _ when is_binary(Value) ->
              Value;
          _ ->
              case Key of
                  <<"key">> -> to_json(Value);
                  <<"startkey">> -> to_json(Value);
                  <<"endkey">> -> to_json(Value);
                  _ ->
                      lists:flatten(?JSON_ENCODE(Value))
              end
      end.
  
  
  get_var(VarName, Props, Default) ->
      VarName1 = to_binding(VarName),
      couch_util:get_value(VarName1, Props, Default).
  
  %% doc: build new patch from bindings. bindings are query args
  %% (+ dynamic query rewritten if needed) and bindings found in
  
negative.code:                     Bindings1 = Bindings ++ QueryList,
                      % we parse query args from the rule and fill
                      % it eventually with bindings vars
                      QueryArgs1 = make_query_list(QueryArgs, Bindings1,
                          Formats, []),
                      % remove params in QueryLists1 that are already in
                      % QueryArgs1
                      Bindings2 = lists:foldl(fun({K, V}, Acc) ->
  