diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 0441866344..eb4acda64b 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -4639,11 +4639,11 @@ EOF; $safe_text = (string) preg_replace_callback( $regex, static function( $matches ) { - if ( ! $matches[0] ) { + if ( ! isset( $matches[0] ) ) { return ''; } - if ( ! empty( $matches['non_cdata'] ) ) { + if ( isset( $matches['non_cdata'] ) ) { // escape HTML entities in the non-CDATA Section. return _wp_specialchars( $matches['non_cdata'], ENT_XML1 ); } diff --git a/tests/phpunit/tests/formatting/escXml.php b/tests/phpunit/tests/formatting/escXml.php index fa6738dca0..435bc398a6 100644 --- a/tests/phpunit/tests/formatting/escXml.php +++ b/tests/phpunit/tests/formatting/escXml.php @@ -42,6 +42,11 @@ class Tests_Formatting_EscXml extends WP_UnitTestCase { "SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1", 'SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1', ), + // Zero string. + array( + '0', + '0', + ), ); }