Skip to content

QueryString.Create(...) excludes key when StringValues is empty #2679

@aspnet-hello

Description

@aspnet-hello

From @austindrenski on Thursday, November 16, 2017 3:49:22 PM

QueryString.Create(IEnumerable<KeyValuePair<string, StringValues>> parameters) doesn't append a key unless it has associated values.

This was unexpected because it means that parsing an incoming query string into an IEnumerable<KeyValuePair<string, StringValues>> and then immediately reconstructing a QueryString results in information loss.

We ran across this after some new middleware attempted to validate parameter values (by treating all query string entries as KeyValuePair<string, StringValues>) and unexpectedly removed a key meant to be read as a switch/flag/indicator in the event no values are supplied.

Is this behavior intentional or defined by a standard?

https://github.com/aspnet/HttpAbstractions/blob/476333771cb7399af13c1368982e2b8abb4318ac/src/Microsoft.AspNetCore.Http.Abstractions/QueryString.cs#L153-L175

Copied from original issue: aspnet/HttpAbstractions#969

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsbreaking-changeThis issue / pr will introduce a breaking change, when resolved / merged.bugThis issue describes a behavior which is not expected - a bug.feature-http-abstractionshelp wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions