-
Notifications
You must be signed in to change notification settings - Fork 116
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
IdCardValidator 不支持null值返回true #479
Comments
我认为可以增加 AllowNull,AllowNullOrEmpty 的属性来控制validation内部判断逻辑。理论上来说验证格式就要符合格式要求,明显null和empty不符合格式要求,返回失败是正确的。但如果明确指定可以为null或empty,那一样返回验证成功只是可选项,而不是默认逻辑。 |
[fluentvalidation]内置了NotNull NotEmpty 这两个校验器,就默认情况它的内置校验器都只校验非null值,可能因为null值没有规则校验意义吧,除非加上这两个之一才会校验非空。 按照Webapi正常而言,如果一个字段没有值,会被是赋予null,如果要逆转这个规则,可以通过这个属性 |
可以,就这样吧。 |
@xyfy 你那边方便改一下吗?除了IdCardValidator之外,还有PhoneValidator也有同样的问题 |
行 |
但是如果这里改了的话,其它已经调用的地方,就得加上notnull来保证校验逻辑的一致性,这个算BreakChange? @zhenlei520 |
是的,需要在发版描述以及1.0.0 文档的升级指南中写清楚 |
1. add `SetValidatorWithCondition` and `WhenIdCard` and `WhenPhone` extension method for optional validator. 2. IdCardValidator and PhoneValidator will pass when given an NULL value 3. adujst unit test case 4. change PasswordValidator base class to `MasaRegularExpressionValidator` Closes #479 BREAKING CHANGE: IdCardValidator and PhoneValidator will pass when given an NULL value , consistent with the logic of the official built-in validator
FluentValidation 忽略Null值 内置正则表达式校验空字符串 提供WhenNotEmpty方法 close: #479
FluentValidation 忽略Null值 内置正则表达式校验空字符串 提供WhenNotEmpty方法 close: #479
@zhenlei520
没有找到一种可以标记可选的办法,理论上应该是Idcard在null或者空的情况下通过校验,靠notempty/notnull来控制是否可空,但是目前IdCardValidator没有
Originally posted by @xyfy in masastack/MASA.Auth#730 (comment)
see the EmailValidator of fluentvalidation
it will return true when value is null
The text was updated successfully, but these errors were encountered: