Make WordPress Core

Changeset 53144


Ignore:
Timestamp:
04/11/2022 07:58:04 PM (3 years ago)
Author:
audrasjb
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r53053 r53144  
    46404640        $regex,
    46414641        static function( $matches ) {
    4642             if ( ! $matches[0] ) {
     4642            if ( ! isset( $matches[0] ) ) {
    46434643                return '';
    46444644            }
    46454645
    4646             if ( ! empty( $matches['non_cdata'] ) ) {
     4646            if ( isset( $matches['non_cdata'] ) ) {
    46474647                // escape HTML entities in the non-CDATA Section.
    46484648                return _wp_specialchars( $matches['non_cdata'], ENT_XML1 );
  • trunk/tests/phpunit/tests/formatting/escXml.php

    r51623 r53144  
    4242                "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",
    4343                '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',
     44            ),
     45            // Zero string.
     46            array(
     47                '0',
     48                '0',
    4449            ),
    4550        );
Note: See TracChangeset for help on using the changeset viewer.