Skip to content

PATTERN validator unexpectedly fails on object values #205

@xificurk

Description

@xificurk

Version: v2.4.x-dev, v3.0.x-dev

Bug Description

PATTERN validator fails on controls that return object values, even if they are castable to string.

Steps To Reproduce

$control = new Nette\Forms\Controls\TextInput;
$control->setValue(new class () {private $lorem = 'ipsum'; function __toString() {return '142';}});
var_dump(Nette\Forms\Validator::validatePattern($control, '\d+')); // false

Expected Behavior

Validation should pass.

Possible Solution

The root cause is in Validator::toArray() method (which is called from Validator::validatePattern()) - it casts the object to array, which leads to some unexpected results. Validator::toArray() should not use array cast on objects.

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