WordPress.org

Make WordPress Core

Opened 3 weeks ago

Closed 3 weeks ago

Last modified 2 weeks 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 Owned by: 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
3 weeks 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
3 weeks 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
3 weeks 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
3 weeks 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
3 weeks 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
3 weeks ago

Thank you!

#7 @dd32
2 weeks ago

#42590 was marked as a duplicate.

Note: See TracTickets for help on using tickets.