Skip to content
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

参数注解顺序和必填验证失效问题 #11

Open
CooleYoung opened this issue Jan 29, 2021 · 1 comment
Open

参数注解顺序和必填验证失效问题 #11

CooleYoung opened this issue Jan 29, 2021 · 1 comment

Comments

@CooleYoung
Copy link

EasySwoole\HttpAnnotation\AnnotationController line(250), 校验的参数被赋值默认null. 导致required不生效, 只能使用notEmpty

  • 以下注解验证必填未生效
@Param(name="name",required="",lengthMin="2",lengthMax="25",alias="姓名")

//未传递name参数, 验证结果如下(必填验证未生效):
// {"code":400,"result":null,"msg":"姓名长度不能超过25"}

提取校验规则顺序是通过EasySwoole\HttpAnnotation\AnnotationTag\Param->allowValidateRule固定顺序进行遍历提取, 不能按照注解的规则顺序进行校验

  • 以下注解验证顺序不对应
@Param(name="url",notEmpty="",url="",lengthMin="5",lengthMax="120",alias="链接地址")

//传递url值为 xx, , 验证结果如下(应当先进行url合法性验证):
 {"code":400,"result":null,"msg":"链接地址长度不能小于5"}
@Player626
Copy link
Contributor

Player626 commented Jan 29, 2021

1、required被调用的时候,不填写任何数据,会成为空字符串, 此时!== null是成立.而required的底层判断是isset函数.
2、没有办法去获取用户的注解规则顺序,肯定也会有人先去判断length,再去判断是否为url.为什么你没有传入数据,会导致报长度错误,是因为此时的值不属于php的标量,所以validatefalse,因此触发参数异常.
3、两个验证规则,ab,a先验证失败和b先验证失败有区别?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants