Bug Report #2988

Validate does not travel recursively through $_POST

Added by Tyler Rasmussen about 4 years ago. Updated about 4 years ago.

Status:ClosedStart date:06/21/2010
Priority:HighDue date:
Assignee:Woody Gilk% Done:

0%

Category:Core
Target version:v3.0.7
Resolution:wontfix Points:

Description

See http://www.php.net/manual/en/arrayobject.construct.php#84206 for possible fix, though the code looks poor and would need improvements.

If $_POST contains any arrays (as the result of a multi-select or checkboxes), new Validate($_POST) converts those arrays to the string "Array" rather than bringing in the $_POST data. This is really an issue that ArrayObject does not take multi-dimensional arrays (at least not in PHP 5.2, which is what I'm working in), but $_POST will often contain multi-dimensional arrays

History

#1 Updated by Tyler Rasmussen about 4 years ago

I was wrong; different issue is why I wasn't getting arrays in my output. I'm using ->filter(TRUE, 'trim') and when running check(), the filter is not traveling recursively through the data, resulting in array to string conversions (line 775, latest GitHub).

I don't think $_POST data every comes with more than 1 extra level of arrays, so a simple solution would be to check if the data is an array, and if so run a for loop.

#2 Updated by Tyler Rasmussen about 4 years ago

For my fix, I replaced line 775 with

if(is_array($params[0]))
{
    foreach($params[0] as $_key => $_value)
    {
        $params[0][$_key] = $function->invokeArgs(array($_value));
    }

    $value = $params[0];
}
else
{
    $value = $function->invokeArgs($params);
}

and line 786 with

if(is_array($params[0]))
{
    foreach($params[0] as $_key => $_value)
    {
        $params[0][$_key] = $method->invokeArgs(NULL, array($_value));
    }

    $value = $params[0];
}
else
{
    $value = $method->invokeArgs(NULL, $params);
}

I haven't gotten to how this affects rules and callbacks yet.

Basically, I think Validate works with the assumption that all fields are strings, so I'm just making it work with the assumption that if a field is an array, all the array's contents will be strings.

#3 Updated by Woody Gilk about 4 years ago

  • Category set to Core
  • Status changed from New to Closed
  • Assignee set to Woody Gilk
  • Resolution set to wontfix

Basically, I think Validate works with the assumption that all fields are strings, so I'm just making it work with the assumption that if a field is an array, all the array's contents will be strings.

You are correct. Validate does not support multi-dimensional arrays. It probably never will, because handling them recursively is nearly impossible. It is recommended to validate sub-arrays separately.

Also available in: Atom PDF