From 84434c7761235107068bf8c2fe159e613523d9f1 Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Sat, 24 Oct 2026 08:44:26 -0600 Subject: [PATCH 1/4] Add failing tests for array input to phone validation and request sanitizing --- tests/phpunit/entries/test_FrmEntryValidate.php | 17 +++++++++++++++++ tests/phpunit/misc/test_FrmAppHelper.php | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/tests/phpunit/entries/test_FrmEntryValidate.php b/tests/phpunit/entries/test_FrmEntryValidate.php index 5a39c3b176..715c18687e 100644 --- a/tests/phpunit/entries/test_FrmEntryValidate.php +++ b/tests/phpunit/entries/test_FrmEntryValidate.php @@ -37,6 +37,23 @@ public function test_validate() { * * @covers FrmEntryValidate::validate */ + /** + * @covers FrmEntryValidate::validate_phone_field + */ + public function test_validate_phone_field_rejects_array_value() { + $field = $this->factory->field->create_and_get( + array( + 'type' => 'phone', + 'form_id' => $this->factory->form->create(), + ) + ); + $errors = array(); + + FrmEntryValidate::validate_phone_field( $errors, $field, array( 'x' ), array( 'id' => $field->id ) ); + + $this->assertArrayHasKey( 'field' . $field->id, $errors ); + } + public function test_pre_validate_entry_filter() { $form_id = $this->factory->form->create(); $field_id = $this->factory->field->create( diff --git a/tests/phpunit/misc/test_FrmAppHelper.php b/tests/phpunit/misc/test_FrmAppHelper.php index 84d0864862..5e4d6b9085 100644 --- a/tests/phpunit/misc/test_FrmAppHelper.php +++ b/tests/phpunit/misc/test_FrmAppHelper.php @@ -251,6 +251,17 @@ public function test_sanitize_request() { $this->assertSame( $values['content'], wp_kses_post( $values['content'] ) ); } + /** + * @covers FrmAppHelper::sanitize_request + */ + public function test_sanitize_request_ignores_array_value() { + $values = array( 'frm_action' => array( 'x' ) ); + + FrmAppHelper::sanitize_request( array( 'frm_action' => 'sanitize_title' ), $values ); + + $this->assertSame( '', $values['frm_action'] ); + } + public function test_kses() { $start_value = ''; $safe_value = 'Hello, click here'; From 896f2a868b7cdfb77f21c0776c1a153c33e72c95 Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Sat, 24 Oct 2026 08:44:36 -0600 Subject: [PATCH 2/4] Place phone test before the next test's docblock --- tests/phpunit/entries/test_FrmEntryValidate.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/entries/test_FrmEntryValidate.php b/tests/phpunit/entries/test_FrmEntryValidate.php index 715c18687e..ae38a3d6d1 100644 --- a/tests/phpunit/entries/test_FrmEntryValidate.php +++ b/tests/phpunit/entries/test_FrmEntryValidate.php @@ -32,11 +32,6 @@ public function test_validate() { remove_filter( 'frm_validate_entry', $add_a_custom_error ); } - /** - * @since 7.0 - * - * @covers FrmEntryValidate::validate - */ /** * @covers FrmEntryValidate::validate_phone_field */ @@ -54,6 +49,11 @@ public function test_validate_phone_field_rejects_array_value() { $this->assertArrayHasKey( 'field' . $field->id, $errors ); } + /** + * @since 7.0 + * + * @covers FrmEntryValidate::validate + */ public function test_pre_validate_entry_filter() { $form_id = $this->factory->form->create(); $field_id = $this->factory->field->create( From cc4ead280b2c3982f90a9c4d7015c818ed51f2d8 Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Sat, 24 Oct 2026 08:48:35 -0600 Subject: [PATCH 3/4] Handle array input in phone validation and request sanitizing --- classes/helpers/FrmAppHelper.php | 2 +- classes/models/FrmEntryValidate.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/helpers/FrmAppHelper.php b/classes/helpers/FrmAppHelper.php index fa9234fec0..d2f1351c36 100644 --- a/classes/helpers/FrmAppHelper.php +++ b/classes/helpers/FrmAppHelper.php @@ -929,7 +929,7 @@ public static function sanitize_request( $sanitize_method, &$values ) { foreach ( $temp_values as $k => $val ) { if ( isset( $sanitize_method[ $k ] ) ) { - $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val ); + $values[ $k ] = is_array( $val ) ? '' : call_user_func( $sanitize_method[ $k ], $val ); } } } diff --git a/classes/models/FrmEntryValidate.php b/classes/models/FrmEntryValidate.php index 4172b40080..1ed176bb1f 100644 --- a/classes/models/FrmEntryValidate.php +++ b/classes/models/FrmEntryValidate.php @@ -494,7 +494,7 @@ public static function validate_phone_field( &$errors, $field, $value, $args ) { $pattern = self::phone_format( $field ); - if ( ! preg_match( $pattern, $value ) ) { + if ( is_array( $value ) || ! preg_match( $pattern, $value ) ) { $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); } } From 65775a3a5e32d2882b61d946ad4a3766eaf4f9cd Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Sat, 24 Oct 2026 08:55:27 -0600 Subject: [PATCH 4/4] Fix PHPCS and PHP CS Fixer findings --- classes/models/FrmEntryValidate.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/models/FrmEntryValidate.php b/classes/models/FrmEntryValidate.php index 1ed176bb1f..c474f55a9b 100644 --- a/classes/models/FrmEntryValidate.php +++ b/classes/models/FrmEntryValidate.php @@ -478,10 +478,10 @@ public static function validate_field_types( &$errors, $posted_field, $value, $a } /** - * @param array $errors - * @param object $field - * @param string $value - * @param array $args + * @param array $errors + * @param object $field + * @param array|string $value + * @param array $args * * @return void */