Skip to content
Open
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
2 changes: 1 addition & 1 deletion classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions classes/models/FrmEntryValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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' );
}
}
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/entries/test_FrmEntryValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ public function test_validate() {
remove_filter( 'frm_validate_entry', $add_a_custom_error );
}

/**
* @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 );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryValidate::assertArrayHasKey()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @since 7.0
*
Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/misc/test_FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAppHelper::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

public function test_kses() {
$start_value = '<script></script><script></script>';
$safe_value = 'Hello, <a href="/test">click here</a>';
Expand Down
Loading