Formatting: Loosen the type checking in _sanitize_text_fields().

[44618] added strict type checking to `_sanitize_text_fields()`, which has caused some compat issues with plugins.

We can loosen the type checking to only reject objects and arrays, and cast other types to string.

Props Nick_theGeek, pento.
Fixes #41450.



git-svn-id: https://develop.svn.wordpress.org/trunk@44731 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-02-07 23:34:22 +00:00
parent 2a49b5c469
commit d2f41560d3
2 changed files with 27 additions and 1 deletions

View File

@ -5153,10 +5153,12 @@ function sanitize_textarea_field( $str ) {
* @return string Sanitized string.
*/
function _sanitize_text_fields( $str, $keep_newlines = false ) {
if ( ! is_string( $str ) ) {
if ( is_object( $str ) || is_array( $str ) ) {
return '';
}
$str = (string) $str;
$filtered = wp_check_invalid_utf8( $str );
if ( strpos( $filtered, '<' ) !== false ) {

View File

@ -97,6 +97,30 @@ class Tests_Formatting_SanitizeTextField extends WP_UnitTestCase {
array(),
'',
),
array(
array( 1, 2, 'foo' ),
'',
),
array(
new WP_Query,
'',
),
array(
2,
'2',
),
array(
false,
'',
),
array(
true,
'1',
),
array(
10.1,
'10.1',
),
);
}