Replicator: encode query string parameter values According to RFC3986 [1], characters like "[", "]" and "," must be percent encoded when used in values of query string parameters. One such query parameter example is ?open_revs whose value is a JSON array of strings (which always contains "[", "]" and ",").
[1] http://tools.ietf.org/html/rfc3986#section-2.2 Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/ebb5c6df Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/ebb5c6df Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/ebb5c6df Branch: refs/heads/master Commit: ebb5c6dfc2ae64d22f04275025c79f6358b3b446 Parents: 2e48678 Author: Filipe David Borba Manana <[email protected]> Authored: Thu Nov 17 18:11:46 2011 +0000 Committer: Filipe David Borba Manana <[email protected]> Committed: Thu Nov 17 18:11:46 2011 +0000 ---------------------------------------------------------------------- src/couchdb/couch_api_wrap.erl | 9 ++++++--- src/couchdb/couch_api_wrap_httpc.erl | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/ebb5c6df/src/couchdb/couch_api_wrap.erl ---------------------------------------------------------------------- diff --git a/src/couchdb/couch_api_wrap.erl b/src/couchdb/couch_api_wrap.erl index bb8d983..d2f3b3a 100644 --- a/src/couchdb/couch_api_wrap.erl +++ b/src/couchdb/couch_api_wrap.erl @@ -445,7 +445,8 @@ options_to_query_args(HttpDb, Path, Options) -> HttpDb, [{path, Path}, {qs, QueryArgs1}]), RevList = atts_since_arg( length("GET " ++ FullUrl ++ " HTTP/1.1\r\n") + - length("&atts_since=[]"), PAs, []), + length("&atts_since=") + 6, % +6 = % encoded [ and ] + PAs, []), [{"atts_since", ?JSON_ENCODE(RevList)} | QueryArgs1] end. @@ -473,9 +474,11 @@ atts_since_arg(UrlLen, [PA | Rest], Acc) -> RevStr = couch_doc:rev_to_str(PA), NewUrlLen = case Rest of [] -> - UrlLen + size(RevStr) + 2; % plus 2 double quotes + % plus 2 double quotes (% encoded) + UrlLen + size(RevStr) + 6; _ -> - UrlLen + size(RevStr) + 3 % plus 2 double quotes and a comma + % plus 2 double quotes and a comma (% encoded) + UrlLen + size(RevStr) + 9 end, case NewUrlLen >= ?MAX_URL_LEN of true -> http://git-wip-us.apache.org/repos/asf/couchdb/blob/ebb5c6df/src/couchdb/couch_api_wrap_httpc.erl ---------------------------------------------------------------------- diff --git a/src/couchdb/couch_api_wrap_httpc.erl b/src/couchdb/couch_api_wrap_httpc.erl index f1ef7d3..d05eec7 100644 --- a/src/couchdb/couch_api_wrap_httpc.erl +++ b/src/couchdb/couch_api_wrap_httpc.erl @@ -215,7 +215,7 @@ query_args_to_string([], []) -> query_args_to_string([], Acc) -> "?" ++ string:join(lists:reverse(Acc), "&"); query_args_to_string([{K, V} | Rest], Acc) -> - query_args_to_string(Rest, [K ++ "=" ++ V | Acc]). + query_args_to_string(Rest, [K ++ "=" ++ couch_httpd:quote(V) | Acc]). oauth_header(#httpdb{oauth = nil}, _ConnParams) ->
