Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

FormUrlEncodedJson calls wrong overload of Error.Argument

未关闭
#431 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
csharp
领域
api, backend

调研方向

从 src/System.Net.Http.Formatting/Formatting/FormUrlEncodedJson.cs 开始,重点检查 FormUrlEncodedJson.AddToArray,并将其中对 Error.Argument 的调用与 src/Common/Error.cs 中的重载进行比较。确认仅使用格式字符串和格式参数的调用会解析到预期的重载;当格式字符串不再被视为参数名时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

src/System.Net.Http.Formatting/Formatting/FormUrlEncodedJson.cs contains several Error.Argument calls that do not specify the parameter name. For example, in the FormUrlEncodedJson.AddToArray method:

https://github.com/aspnet/AspNetWebStack/blob/1231b77d79956152831b75ad7f094f844251b97f/src/System.Net.Http.Formatting/Formatting/FormUrlEncodedJson.cs#L400-L404

The arguments in this call are a format string from resources, and a string to use as a format argument. The call is intended to go to the internal static ArgumentException Argument(string messageFormat, params object[] messageArgs) method that is defined here:

https://github.com/aspnet/AspNetWebStack/blob/a55e96a451393aa854556ac9feb2d80e81988a9c/src/Common/Error.cs#L37-L40

Instead, it goes to the internal static ArgumentException Argument(string parameterName, string messageFormat, params object[] messageArgs) method that is defined here:

https://github.com/aspnet/AspNetWebStack/blob/a55e96a451393aa854556ac9feb2d80e81988a9c/src/Common/Error.cs#L49-L52

The format string that was read from Properties.Resources.FormUrlEncodedMismatchingTypes thus becomes misused as the parameter name.

I have not tried to reproduce this bug in practice, but the incorrect call is evident from the IL disassembly of lib/netstandard2.0/System.Net.Http.Formatting.dll in the Microsoft.AspNet.WebApi.Client 6.0.0 package:

  IL_001b:  call       string System.Net.Http.Properties.Resources::get_FormUrlEncodedMismatchingTypes()
  IL_0020:  ldarg.1
  IL_0021:  ldarg.1
  IL_0022:  ldlen
  IL_0023:  conv.i4
  IL_0024:  ldc.i4.1
  IL_0025:  sub
  IL_0026:  call       string System.Net.Http.Formatting.FormUrlEncodedJson::BuildPathString(string[],
                                                                                             int32)
  IL_002b:  call       !!0[] [netstandard]System.Array::Empty<object>()
  IL_0030:  call       class [netstandard]System.ArgumentException System.Web.Http.Error::Argument(string,
                                                                                                   string,
                                                                                                   object[])
  IL_0035:  throw

In the Microsoft.AspNet.WebApi.Client 4.0.20505 package (released on 31 May 2012), the FormUrlEncodedJson.AddToArray method did not have this bug yet. In the Microsoft.AspNet.WebApi.Client 4.0.20710 package (released on 11 August 2012), the method had the bug. I think the bug was introduced by commit f19f4683cc36ebb2666fa36f6dcd1825f4b214aa in May 2012.

Because the bug is so old and is not known to cause any problems in practice, I suspect you might decide not to fix it.

主要语言
C#
星标
897
派生
358
平均合并
40 分钟
30 天内合并 PR
1

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

aspnet/AspNetWebStack 的其他 Issue

查看 aspnet/AspNetWebStack 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。