Description
Description
The ToString() function on HttpQSCollection inside of System.Web.HttpUtility does not url encode the names of the name value collection. It does this is .net framework 4.8.
I ran into this issue from PowerShell, but I can see the issue is the .net framework it is built on that has the issue.
I'm currently working on some API calls to Infoblox where I need to pass a query name "_return_fields+=extattrs" for example and the + char is normally encoded to %2b and running in full .net framwork this works as intended, but in .net core an hence PowerShell 6+ it does not work.
I believe this is a bug and related to this specific line of code, where the key part of the string is not urlencoded.
https://github.com/dotnet/runtime/blob/v8.0.1/src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs#L70
Reproduction Steps
Cosole applicaton to show the decode function decodes names correctly and back to query string from the collection.
using System;
using System.Web;
//inputstring
var queryString = "_return_fields%2b=extattrs&name%3a=somename.somedomain.local";
Console.WriteLine($"Query string input: {queryString}");
//parse
var nameValues = HttpUtility.ParseQueryString(queryString);
//show paring decodes the name part
foreach (var key in nameValues.AllKeys)
{
Console.WriteLine($"Key: {key} => Value: {nameValues[key]}");
}
//call tostring to make the namevalues to query string
Console.WriteLine($"Query string output: {nameValues.ToString()}");
Expected behavior
Expected output where the +
is encoded as %2b
and :
as %3a
Query string input: _return_fields%2b=extattrs&name%3a=somename.somedomain.local
Key: _return_fields+ => Value: extattrs
Key: name: => Value: somename.somedomain.local
Query string output: _return_fields%2b=extattrs&name%3a=somename.somedomain.local
Actual behavior
This is the output I get from .net core version 8.0.1, note the output string the +
and :
signs are not encoded as they should
Query string input: _return_fields%2b=extattrs&name%3a=somename.somedomain.local
Key: _return_fields+ => Value: extattrs
Key: name: => Value: somename.somedomain.local
Query string output: _return_fields+=extattrs&name:=somename.somedomain.local
Regression?
This works as expected in full .NET framework 4.8 so it is a regression since core framework I believe.
This also works in Windows PowerShell 5.1 which is built on .net framework v 4.5
Known Workarounds
No response
Configuration
.NET Core 8.0.101 Windows 11 23H2 x64
Also on PowerShell 7.4.1 (.net core 8 based) running on Windows 10 x64
Other information
No response