Make WordPress Core

Ticket #50145: 50145.2.patch

File 50145.2.patch, 2.7 KB (added by Clorith, 6 years ago)
  • src/js/_enqueues/admin/site-health.js

     
    6666                $( this ).attr( 'aria-expanded', ! goodIssuesWrapper.hasClass( 'hidden' ) );
    6767        } );
    6868
     69        /**
     70         * Validates the Site Health test result format.
     71         *
     72         * @since 5.6.0
     73         *
     74         * @param {Object} issue
     75         *
     76         * @return {boolean}
     77         */
     78        function validateIssueData( issue ) {
     79                // Expected minimum format of a valid SiteHealth test response.
     80                var minimumExpected = {
     81                        test: 'string',
     82                        label: 'string',
     83                        description: 'string'
     84                };
     85                var passed = true;
     86
     87                // If the issue passed is not an object, return a `false` state early.
     88                if ( 'object' !== typeof( issue ) ) {
     89                        return false;
     90                }
     91
     92                // Loop over expected data and match the data types.
     93                for ( var key in minimumExpected ) {
     94                        var value = minimumExpected[ key ];
     95
     96                        if ( 'object' === typeof( value ) ) {
     97                                for ( var subKey in value ) {
     98                                        var subValue = value[ subKey ];
     99
     100                                        if (
     101                                                'undefined' === typeof( issue[ key ] ) ||
     102                                                'undefined' === typeof( issue[ key ][ subKey ] ) ||
     103                                                subValue !== typeof( issue[ key ][ subKey ] )
     104                                        ) {
     105                                                passed = false;
     106                                        }
     107                                }
     108                        } else {
     109                                if (
     110                                        'undefined' === typeof( issue[ key ] ) ||
     111                                        value !== typeof( issue[ key ] )
     112                                ) {
     113                                        passed = false;
     114                                }
     115                        }
     116                }
     117
     118                return passed;
     119        }
     120
    69121        /**
    70122         * Appends a new issue to the issue list.
    71123         *
     
    78130                        issueWrapper = $( '#health-check-issues-' + issue.status ),
    79131                        heading,
    80132                        count;
    81                
     133
     134                /*
     135                 * Validate the issue data format before using it.
     136                 * If the output is invalid, discard it.
     137                 */
     138                if ( ! validateIssueData( issue ) ) {
     139                        return false;
     140                }
     141
    82142                SiteHealth.site_status.issues[ issue.status ]++;
    83143
    84144                count = SiteHealth.site_status.issues[ issue.status ];
  • src/wp-admin/site-health.php

     
    144144        <h4 class="health-check-accordion-heading">
    145145                <button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-{{ data.test }}" type="button">
    146146                        <span class="title">{{ data.label }}</span>
    147                         <span class="badge {{ data.badge.color }}">{{ data.badge.label }}</span>
     147                        <# if ( data.badge ) { #>
     148                                <span class="badge {{ data.badge.color }}">{{ data.badge.label }}</span>
     149                        <# } #>
    148150                        <span class="icon"></span>
    149151                </button>
    150152        </h4>