Skip to content

Commit b443ae3

Browse files
authored
Merge pull request #172 from sagadira/CSCwu08056
fix(csharp): numeric .NET version check to prevent double URL-encoding on .NET 9+ (CSCwu08056)
2 parents 65df3c2 + 20cf96f commit b443ae3

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,17 @@ namespace {{packageName}}.Client
130130
}
131131

132132
var httpValues = HttpUtility.ParseQueryString(string.Empty);
133+
#if (NETCOREAPP)
134+
// On .NET 9+, ParseQueryString already URL-encodes values.
135+
// Skip UrlEncode to prevent double-encoding that causes signature mismatches.
136+
string framework = RuntimeInformation.FrameworkDescription;
137+
bool skipUrlEncode = framework.StartsWith(".NET ") &&
138+
int.TryParse(framework.Substring(5).Split('.')[0], out int major) && major >= 9;
139+
#endif
133140
foreach (var parameter in requestOptions.QueryParameters)
134141
{
135142
#if (NETCOREAPP)
136-
string framework = RuntimeInformation.FrameworkDescription;
137-
string key = framework.StartsWith(".NET 9")?parameter.Key:HttpUtility.UrlEncode(parameter.Key);
143+
string key = skipUrlEncode ? parameter.Key : HttpUtility.UrlEncode(parameter.Key);
138144
if (parameter.Value.Count > 1)
139145
{ // array
140146
foreach (var value in parameter.Value)

0 commit comments

Comments
 (0)