yii2: StringValidator not failing when sent a true boolean type.
What steps will reproduce the problem?
Establish a 'string' rule on an attribute in a Model (ActiveRecord in my case).
POST a JSON object containing a true for that attribute.
What is the expected result?
Similarly to how POSTing a false to that attribute will generate an error about the attribute being empty, I would expect the same for a true
What do you get instead?
The attribute received a '1' as its new value.
Additional info
I verified the getBodyParam('attribute') is returning the boolean however I noticed in StringValidator.validateAttribute() that the $value is a '1' at that point which is why the attribute is not failing the validation.
| Q | A |
|---|---|
| Yii version | 2.0.11.2 |
| PHP version | 7.0.13 |
| Operating system | ubuntu 4.9.5-moby |
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (9 by maintainers)
Commits related to this issue
- trim unreliable for boolean types...https://github.com/yiisoft/yii2/issues/13701 — committed to silinternational/idp-id-broker by deleted user 7 years ago
@wcjr sure, I’ll definitely have a look at what’s going on there.
@wcjr
trimvalidator you use convertstrueto'0'andfalseto an empty string.@wcjr it would help a lot to debug this if you make a fork of the basic app with minimal possible changes that reproduce the issue or a failing unit-test.