8000 [Bug]: Query parameters in path are reversed · Issue #1732 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[Bug]: Query parameters in path are reversed #1732
Closed
@TimothyMakkison

Description

@TimothyMakkison

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])
        );
    }
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0