zendframework / zend-validator

Validator component from Zend Framework
BSD 3-Clause "New" or "Revised" License
181 stars 136 forks source link

Between Validator outputs true for characters #167

Closed koseduhemak closed 7 years ago

koseduhemak commented 7 years ago

Hi,

I am using version "2.9.0 - 2017-03-17" of zendframework/zend-validator. If I input string "asdasd" for field "price" validator returns true. Expecting: false.

String "asdasd" is not even a number. Therefore it cannot lie between 0 and 99999999.


public function init() {
     $this->add(array(
            'type' => 'text',
            'name' => 'price',
            'options' => array(
                'label' => $this->translator->translate('label.price', 'Form'),
                'label_attributes' => array(
                    'class' => 'col-sm-3',
                ),
                'column-size' => 'sm-5',
            ),
            'attributes' => array(
                'id' => 'price',
            ),
        ));
}

public function getInputFilterSpecification()
    {
        return array(
            'price' => array(
                'required' => true,
                'validators' => array(
                    array(
                        'name' => 'Between',
                        'options' => array(
                            'min' => 0,
                            'max' => 99999999,
                            'inclusive' => true
                        ),
                    ),
                ),
            ),
        );
    }
Ocramius commented 7 years ago

It most likely evaluates as 1 via implicit cast. What happens if 'min' is 2?

koseduhemak commented 7 years ago

if I use 2 it works as expected. How can I change implicit casting behavior to check in a typesafe way? I am struggling to validate integer / float input in my text fields...

Ocramius commented 7 years ago

@koseduhemak I'd say it needs to be considered a bug, given a failing test case and fixed.