-
Notifications
You must be signed in to change notification settings - Fork 10.3k
QueryStringEnumerable API #33910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QueryStringEnumerable API #33910
Conversation
Previously, the logic would trim leading whitespace from keys, but only for keys with a value. I don't know why we did this, why we didn't trim trailing whitespace, and why we didn't do it for keys with empty value. Also it was inconsistent - we did it in QueryHelper, but not in QueryFeature.
@@ -13,6 +13,7 @@ | |||
</PropertyGroup> | |||
|
|||
<ItemGroup> | |||
<Compile Include="$(SharedSourceRoot)QueryStringEnumerable.cs" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for shared-source is that, in a PR coming very soon to a repo near you, I'll be using QueryStringEnumerable
as an internal API inside Microsoft.AspNetCore.Components
. That package does not have a dependency on WebUtilities
, and doesn't want to have one, since it's not web-specific and most of the baggage brought with WebUtilities
would not be applicable.
A query string shouldn't have any white space in it prior to un-escaping keys and values. This code goes all the way back to Katana where the same parser was shared across a few similar formats like query, form, etc.: We've since split each of those up into their own parsers, but apparently there were leftovers. |
Can you clarify this point? Are you saying the scenario is not applicable so we don't need to care about it? Or are you saying we must trim whitespace (and if so, why is it OK not to trim trailing whitespace, and why doesn't the I'm guessing you mean the scenario isn't applicable, presumably because HTTP doesn't have a way to represent unencoded whitespace in the request line. Is that right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any thoughts on adding a new (extension?) method to QueryString that exposed this new enumerator? QueryString.GetEnumerator()
?
It's not applicable an can be ignored because a well formed URI does not allow whitespace anywhere, they must be escaped. This isn't even an HTTP specific requirement. |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
|
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
Hello @SteveSandersonMS! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Implements #33840, hopefully covering the suggestions already raised there.
Fixing an inconsistency (or not?)
There was a weird inconsistency in the parsing behavior regarding whitespace.
QueryHelpers.ParseQuery
previously trimmed any leadingchar.IsWhiteSpace
characters from the key (but not any trailing ones from the key, and not either leading or trailing ones from the value)QueryFeature
's querystring parser did not do that (it retained whitespace at both ends of key and value)The behavior in
QueryHelpers.ParseQuery
doesn't really make sense to me. Why only trim leading and not trailing? Why do none of the unit tests cover this? Why didn'tQueryFeature
have the same behavior? Also note that it was done at the cost of stepping through a potentially 8kb-long string character-by-character.To clean this up, and since the logic in
QueryFeature
looks newer, I've standardized on the don't-trim behavior in the new common logic.Does anyone know why the weird sometimes-trimming behavior existed before? Apparently it's been there for 7 years and is too far back to even see the original commit by following normal GitHub links. I'm happy to put it back if there's a reason, or if this raises a serious concern about breaking. If we are putting it back, do we want to retain the inconsistency between
QueryHelpers
andQueryFeature
, or shouldQueryFeature
also get this odd behavior? Or should we regard the change as breaking and do an announcement?