WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 5 months ago

#28300 new defect (bug)

Two issues in the code for auto-uploading to subfolders

Reported by: wiziapp Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Upgrade/Install Keywords: needs-patch
Focuses: Cc:
PR Number:

Description (last modified by ocean90)

There are two issues in the code for auto-uploading to subfolders within a change rooted FTP (wp-admin/includes/class-wp-filesystem-base.php).

First, it adds a "/" to the replacement expression when the source replacement already contains a "/" (Note that ABSPATH has a trailing slash):

$potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder );

This should be:

$potential_folder = preg_replace( '#^' . preg_quote( trailingslashit($dir), '#' ) . '#i', trailingslashit( constant( $constant ) ), $folder );

Second, it checks that the directory exists. This is not the case during theme and plugin installs, where the not existing directory is specified. Instead, only the parent should be checked.

After:

if ( $this->is_dir( $potential_folder ) ) {
    $this->cache[ $folder ] = $potential_folder;
    return $potential_folder;
}

Adding:

else {
      $potential_parent_folder = trailingslashit(preg_replace('#[^/]*/$#', '', $potential_folder));
      if ( $this->is_dir( $potential_parent_folder ) ) {
            $this->cache[ $folder ] = $potential_folder;
            return $potential_folder;
      }
}

Would test for a valid parent, instead. (E.g. wp-content/themes instead of wp-content/themes/newtheme)

Change History (2)

#1 @ocean90
5 years ago

  • Description modified (diff)

#2 @chriscct7
4 years ago

  • Keywords needs-patch added
Note: See TracTickets for help on using tickets.