Skip to content

Regex segment local evaluation with getype cast expression as int #71

@floranpagliai

Description

@floranpagliai

Hello,

We encountered a bug after defining a regex segment with the following regex ^\d*[13579]$, after a lot of investigation we found that the code cast the expression as an int, making the regex useless and hazardous. We added dumps to the code in order to help you understand the bug.

class SegmentConditionModel
{
    public function matchesTraitValue($traitValue): bool
    {
        $condition = false;
        $castedValue = $this->value;
        $traitValueType = gettype($traitValue);

        dump($castedValue); // "^\d*[13579]$"
        dump($traitValueType); // "integer"
        dump($this->operator); "REGEX"
        if ($traitValueType == 'boolean') {
            $castedValue = filter_var($castedValue, FILTER_VALIDATE_BOOLEAN);
        } elseif ($this->operator === SegmentConditions::MODULO) {
            return $this->matchesModuloTraitValue($traitValue);
        } else {
            settype($castedValue, $traitValueType);
        }
        dump($castedValue); // 0
    }
}

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