Make WordPress Core


Ignore:
Timestamp:
03/16/2023 04:12:51 PM (13 months ago)
Author:
SergeyBiryukov
Message:

Filesystem API: Return false for empty paths in FTP ::exists() methods.

When ftp_nlist() receives an empty path, it checks the current working directory and may return true.

This affects:

  • WP_Filesystem_FTPext::exists()
  • WP_Filesystem_ftpsockets::exists()

As the purpose of the API is to provide a consistent interface for various filesystem implementations, this commit updates the affected methods to returns false when an empty path is provided, bringing consistency with the other filesystem abstraction classes, specifically WP_Filesystem_Direct and WP_Filesystem_SSH2.

Follow-up to [6779], [11821], [25274], [31815].

Props mkox, costdev, Zdrobau, dd32, pbiron, azaozz, mukesh27, SergeyBiryukov.
Fixes #33058.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpext.php

    r55354 r55556  
    420420     *
    421421     * @since 2.5.0
     422     * @since 6.3.0 Returns false for an empty path.
    422423     *
    423424     * @param string $path Path to file or directory.
     
    425426     */
    426427    public function exists( $path ) {
     428        /*
     429         * Check for empty path. If ftp_nlist() receives an empty path,
     430         * it checks the current working directory and may return true.
     431         *
     432         * See https://core.trac.wordpress.org/ticket/33058.
     433         */
     434        if ( '' === $path ) {
     435            return false;
     436        }
     437
    427438        $list = ftp_nlist( $this->link, $path );
    428439
Note: See TracChangeset for help on using the changeset viewer.