Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#42628 closed defect (bug) (fixed)

New function flatten_dirlist in 4.9 does't play nice with folders with numeric names

Reported by: edo888's profile edo888 Owned by: dd32's profile dd32
Milestone: 4.9.1 Priority: normal
Severity: normal Version: 4.9
Component: Upgrade/Install Keywords: needs-patch
Focuses: administration Cc:

Description

Hi,

When you have folders with numeric names in your plugin the flatten_dirlist function will replace the filename(folder name) with 0. Since the plugin usually doesn't have a folder with 0 name it becomes unwritable and plugin update fails. This happens, because flatten_dirlist function uses array_merge function which doesn't preserve the keys and does re-indexing. http://php.net/manual/en/function.array-merge.php

wp-admin/includes/class-wp-upgrader.php:

<?php
        protected function flatten_dirlist( $nested_files, $path = '' ) {
                $files = array();                                        
                                                                         
                foreach ( $nested_files as $name => $details ) {         
                        $files[ $path . $name ] = $details;              
                                                                         
                        // Append children recursively                   
                        if ( ! empty( $details['files'] ) ) {            
                                $children = $this->flatten_dirlist( $details['files'], $path . $name . '/' );
                                                                         
                                $files = array_merge( $files, $children );
                        }                                                
                }                                                        


                return $files;
        }

As you see currently it uses

<?php
$files = array_merge( $files, $children );

It should be

<?php
$files = $files + $children;

so the folders with numeric names will be preserved.

Thanks!

Change History (7)

#1 @dd32
7 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.9.1

Hi @edo888 and thanks for reporting this, I'm moving it to 4.9.1 for review.

Are you aware of any plugins hosted on WordPress.org which are affected by this?

#2 @edo888
7 years ago

@dd32 You can check GTranslate plugin https://wordpress.org/plugins/gtranslate/

You can install version 2.8.31 and try to update to the latest version.

Thanks!

#3 @dd32
7 years ago

  • Owner set to dd32
  • Status changed from new to accepted

Thanks @edo888 !

Including for reference - #41524 - Unfortunately I missed the numeric case there, had I have kept the patch there as-is it'd not have been a problem :)

#4 @dd32
7 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 42214:

Upgrade: Fix updating plugins which include a numeric file/folder names.
The fix in [41821] caused numeric folder names to be reindexed to 0..n when in the root directory (for example, my-plugin/24/).

Props edo888.
See #41524.
Fixes #42628 for trunk.

#5 @dd32
7 years ago

In 42215:

Upgrade: Fix updating plugins which include a numeric file/folder names.
The fix in [41821] caused numeric folder names to be reindexed to 0..n when in the root directory (for example, my-plugin/24/).

Props edo888.
See #41524.
Merges [42214] to the 4.9 branch.
Fixes #42628 for 4.9.

#6 @edo888
7 years ago

Thank you!

#7 @dd32
7 years ago

#42590 was marked as a duplicate.

Note: See TracTickets for help on using tickets.