You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the Size rule assumes it will receive a string or number (int/float). This is problematic when validating request data that often comes in as string values. Intuitively, if the size rule is combined with numeric, then the value should be sanitized first as a number before validating.
Workaround by extending the Rule locally and adding sanitize based on value
public function sanitize($value)
{
if (is_numeric($value)) {
if (strpos($value, '.') !== false) {
return (float)$value;
}
return (int)$value;
}
return $value;
}
Proposed solution
Instead of sanitizing based on value, check if numeric or other number related rule is being used as well.
The text was updated successfully, but these errors were encountered:
When building this, I made the conscious decision to rely more on types to inform how validations work. I understand that, practically, often times what's being validated is user input which comes in as a string, but now always. It also makes validation rules more complex as they're having to infer more from the value and sibling rules.
Currently, there's an integer rule which can be used before size to cast it properly. It sounds like if we add a float rule, that would help this use case.
As we discussed, I like the idea of having min, max, and (maybe) size rules that correspond to numeric values - and for character length specific rules we use minLength, maxLength like native html rules work: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/minlength.
Another thing about the size rule I noticed, is that the constructor types the size as an integer. For the use case I need it for (possibility of floats) that size would need to just be numeric, get sanitized as int, float, or string - then do a comparison with the value (that would also need to be sanitized). I'm open to discussion about creating a new rule for these types of scenarios something like equals, same, digits, or is:value.
Currently, the Size rule assumes it will receive a string or number (int/float). This is problematic when validating request data that often comes in as string values. Intuitively, if the size rule is combined with numeric, then the value should be sanitized first as a number before validating.
Workaround by extending the Rule locally and adding sanitize based on value
Proposed solution
Instead of sanitizing based on value, check if numeric or other number related rule is being used as well.
The text was updated successfully, but these errors were encountered: