Make WordPress Core

Ticket #36308: trac-36308-minor-cs-follow-up.patch

File trac-36308-minor-cs-follow-up.patch, 1.2 KB (added by jrf, 21 months ago)

Minor CS fixes for path_is_absolute()

  • src/wp-includes/functions.php

    From 8d0bdaa0f2b46251fc36ca488a4a164a0f46f210 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Wed, 24 Aug 2022 19:38:24 +0200
    Subject: [PATCH] path_is_absolute(): use strict comparisons
    
    Both of these can (and should) be changed to strict comparisons.
    * `strlen()` will only ever return an integer, so can safely use a strict comparison.
    * `realpath()` will return a `string|false`, which means the loose condition currently in place is dangerous as `false` would be regarded as "equal" to an empty string `$path`, which is wrong.
    ---
     src/wp-includes/functions.php | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 16462b07dc..5da48da1f4 100644
    a b function path_is_absolute( $path ) { 
    21012101         * This is definitive if true but fails if $path does not exist or contains
    21022102         * a symbolic link.
    21032103         */
    2104         if ( realpath( $path ) == $path ) {
     2104        if ( realpath( $path ) === $path ) {
    21052105                return true;
    21062106        }
    21072107
    2108         if ( strlen( $path ) == 0 || '.' === $path[0] ) {
     2108        if ( strlen( $path ) === 0 || '.' === $path[0] ) {
    21092109                return false;
    21102110        }
    21112111