Make WordPress Core

Ticket #56791: 56791-always-use-strict-comparisons-when-using-in_array.patch

File 56791-always-use-strict-comparisons-when-using-in_array.patch, 2.1 KB (added by jrf, 18 months ago)

This fixes three out of the four currently flagged issues for in_array() usage. These three all do comparisons with strings, so all the more reason why it is imperative that a strict comparison is used.

  • src/wp-includes/class-wp-block-type.php

    From 9c45d9c140e0f521df981b0eb5319ffff97a3e70 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Fri, 1 Jul 2022 16:23:02 +0200
    Subject: [PATCH] CS/QA: always use strict comparisons when using `in_array()`
    
    ---
     src/wp-includes/class-wp-block-type.php | 6 +++---
     src/wp-includes/pluggable.php           | 2 +-
     2 files changed, 4 insertions(+), 4 deletions(-)
    
    diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php
    index 505c504037..3b3787740a 100644
    a b class WP_Block_Type { 
    299299         *                                   null when value not found, or void when unknown property name provided.
    300300         */
    301301        public function __get( $name ) {
    302                 if ( ! in_array( $name, $this->deprecated_properties ) ) {
     302                if ( ! in_array( $name, $this->deprecated_properties, true ) ) {
    303303                        return;
    304304                }
    305305
    class WP_Block_Type { 
    327327         *                     or false otherwise.
    328328         */
    329329        public function __isset( $name ) {
    330                 if ( ! in_array( $name, $this->deprecated_properties ) ) {
     330                if ( ! in_array( $name, $this->deprecated_properties, true ) ) {
    331331                        return false;
    332332                }
    333333
    class WP_Block_Type { 
    346346         * @param mixed  $value Property value.
    347347         */
    348348        public function __set( $name, $value ) {
    349                 if ( ! in_array( $name, $this->deprecated_properties ) ) {
     349                if ( ! in_array( $name, $this->deprecated_properties, true ) ) {
    350350                        $this->{$name} = $value;
    351351                        return;
    352352                }
  • src/wp-includes/pluggable.php

    diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php
    index 2852e23a93..013e0632a8 100644
    a b if ( ! function_exists( 'get_avatar' ) ) : 
    28792879                        $extra_attr .= "loading='{$loading}'";
    28802880                }
    28812881
    2882                 if ( in_array( $args['decoding'], array( 'async', 'sync', 'auto' ) ) && ! preg_match( '/\bdecoding\s*=/', $extra_attr ) ) {
     2882                if ( in_array( $args['decoding'], array( 'async', 'sync', 'auto' ), true ) && ! preg_match( '/\bdecoding\s*=/', $extra_attr ) ) {
    28832883                        if ( ! empty( $extra_attr ) ) {
    28842884                                $extra_attr .= ' ';
    28852885                        }