Make WordPress Core

Changeset 55556


Ignore:
Timestamp:
03/16/2023 04:12:51 PM (21 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.

Location:
trunk/src/wp-admin/includes
Files:
2 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
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r55354 r55556  
    422422     *
    423423     * @since 2.5.0
     424     * @since 6.3.0 Returns false for an empty path.
    424425     *
    425426     * @param string $path Path to file or directory.
     
    427428     */
    428429    public function exists( $path ) {
     430        /*
     431         * Check for empty path. If ftp::nlist() receives an empty path,
     432         * it checks the current working directory and may return true.
     433         *
     434         * See https://core.trac.wordpress.org/ticket/33058.
     435         */
     436        if ( '' === $path ) {
     437            return false;
     438        }
     439
    429440        $list = $this->ftp->nlist( $path );
    430441
Note: See TracChangeset for help on using the changeset viewer.