Skip to content

Size rule should be aware of additional numeric rule #7

@jonwaldstein

Description

@jonwaldstein

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions