[Bug]: Query parameters in path are reversed
TimothyMakkison opened this issue ยท 1 comments
TimothyMakkison commented
Describe the bug ๐
Query parameters defined in the path are reversed in the resulting request.
Step to reproduce
See RequestBuilderTests.ParametersShouldBePutAsExplicitQueryString
.
[Get("/query?q1={param1}&q2={param2}")]
Task QueryWithExplicitParameters(string param1, string param2);
Becomes /query?q2=value2&q1=value1
Reproduction repository
https://github.com/reactiveui/refit
Expected behavior
Expected /query?q1=value1&q2=value2
Cause
The code that causes this is found in RequestBuilderImplementation
, path queries are readded to queryParamsToAdd
to the start using insert. We can prevent this by either iterating query.AllKeys
in reverse or by keeping count of how many items have been prepended and using this number as an insert index.
var query = HttpUtility.ParseQueryString(uri.Query ?? "");
foreach (var key in query.AllKeys)
{
if (!string.IsNullOrWhiteSpace(key))
{
queryParamsToAdd.Insert(
0,
new KeyValuePair<string, string?>(key, query[key])
);
}
}
github-actions commented
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.