Formatting: Avoid escaping valid XML values in esc_xml().

This change improves the `esc_xml()` function by replacing two `empty()` checks with `isset()` to cover values that are not equal to `''` but still returning `true` when checked with `empty()`, like `'0'`, `0` or `false`. It also updates the related unit tests accordingly.

Props rumpel2116, pbiron.
Fixes #55399.


git-svn-id: https://develop.svn.wordpress.org/trunk@53144 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras
2022-04-11 19:58:04 +00:00
parent 0453d1bc0d
commit 4ee40e3ff1
2 changed files with 7 additions and 2 deletions
+2 -2
View File
@@ -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 );
}