Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion includes/fields/class-acf-field-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,14 @@ public function update_value( $value, $post_id, $field ) {

// Format array of values.
// - Parse each value as string for SQL LIKE queries.
// - Guard against nested arrays (e.g. crafted POST input) by stringifying scalars only.
if ( is_array( $value ) ) {
$value = array_map( 'strval', $value );
$value = array_map(
static function ( $v ) {
return is_scalar( $v ) ? strval( $v ) : '';
},
$value
);
}

// Save custom options back to the field definition if configured.
Expand Down
25 changes: 25 additions & 0 deletions tests/php/includes/fields/test-class-acf-field-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,31 @@ public function test_update_value_converts_to_strings() {
$this->assertContains( 'blue', $result );
}

/**
* Test update_value handles a nested-array value without emitting
* an "Array to string conversion" warning.
*
* A crafted POST such as acf[field_key][0][]=x produces a value where an
* element is itself an array. update_value stringifies submitted values, and
* array_map( 'strval', ... ) on such input triggers a PHP warning. The field
* should handle this gracefully rather than emit the diagnostic.
*
* PHPUnit is configured with convertWarningsToExceptions, so an
* "Array to string conversion" warning would surface as a test failure.
*/
public function test_update_value_nested_array() {
$field = $this->get_field( array( 'multiple' => 1 ) );

$result = $this->field_instance->update_value( array( array( 'x' ) ), $this->post_id, $field );

$this->assertIsArray( $result );

// Every stored value must be a scalar string; nested arrays must not leak through.
foreach ( $result as $stored ) {
$this->assertIsString( $stored );
}
}

/**
* Test get_rest_schema returns valid schema.
*/
Expand Down
Loading