weixin_39985842
weixin_39985842
2021-01-11 10:35

[Netfx bug] CustomValidationAttribute doesn't properly implement RequiresValidationContext

Requested by . We should mark this as netfx-port-consider and close this issue.

See https://github.com/dotnet/corefx/pull/5203, which fixed this.

cs
public class CustomValidator
{
    public static ValidationResult CorrectValidationMethodOneArg(object o) => ValidationResult.Success;
    public static ValidationResult CorrectValidationMethodOneArgStronglyTyped(string s) => ValidationResult.Success;
    public static ValidationResult CorrectValidationMethodTwoArgs(object o, ValidationContext context) => ValidationResult.Success;
    public static ValidationResult CorrectValidationMethodTwoArgsStronglyTyped(TestClass tc, ValidationContext context) => ValidationResult.Success;
}


[Theory]
[InlineData(nameof(CustomValidator.CorrectValidationMethodOneArg), false)]
[InlineData(nameof(CustomValidator.CorrectValidationMethodOneArgStronglyTyped), false)]
[InlineData(nameof(CustomValidator.CorrectValidationMethodTwoArgs), true)]
[InlineData(nameof(CustomValidator.CorrectValidationMethodTwoArgsStronglyTyped), true)]
public static void RequiresValidationContext_Get_ReturnsExpected(string method, bool expected)
{
    CustomValidationAttribute attribute = new CustomValidationAttribute(typeof(CustomValidator), method);

    // The full .NET framework has a bug where CustomValidationAttribute doesn't
    // validate the context. See https://github.com/dotnet/corefx/pull/5203.
    if (PlatformDetection.IsFullFramework)
    {
        Assert.False(attribute.RequiresValidationContext);
    }
    else
    {
        Assert.Equal(expected, attribute.RequiresValidationContext);
    }
}

该提问来源于开源项目:dotnet/runtime

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39983993 weixin_39983993 4月前

    yes -- the tool should pick up the issue even if closed.

    点赞 评论 复制链接分享
  • weixin_39587246 weixin_39587246 4月前

    The PR dotnet/corefx#5203 was already marked as netfx-port-consider. Here's more information, so following 's instructions. (Thanks !)

    点赞 评论 复制链接分享
  • weixin_39633455 weixin_39633455 4月前

    could you please confirm that what the process is for netfx-port-consider? Is including the label on an already merged PR usually enough?

    点赞 评论 复制链接分享
  • weixin_39587246 weixin_39587246 4月前

    created the tool and will likely oversee future .NET Framework porting effort (at least from auditing perspective) - I let him answer. I am inclined to think that PR with the label should be enough ...

    cc

    点赞 评论 复制链接分享

相关推荐