Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#41318 closed enhancement (fixed)

list_files() function bug

Reported by: tkama's profile Tkama Owned by:
Milestone: 4.9 Priority: normal
Severity: normal Version:
Component: Filesystem API Keywords:
Focuses: Cc:


If we set first parameter of list_files( $folder ) with trailing slash, we get incorrect paths in result. Example:

$files = list_files( ABSPATH );

print_r( $files );

    [0] => /home/t/tkamab32/
    [1] => /home/t/tkamab32/
    [2] => /home/t/tkamab32/

We see double slash // in path...

Maybe better to filter incoming $folder parametr with untrailingslashit():

function list_files( $folder = '', $levels = 100 ) {
    if ( empty($folder) )
        return false;

    $folder = untrailingslashit( $folder );


Attachments (2)

41318.diff (446 bytes) - added by xkon 7 years ago.
Created .diff
41318.1.patch (1.4 KB) - added by theorboman 7 years ago.
Patch with unit tests

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
7 years ago

  • Keywords needs-patch needs-unit-tests good-first-bug added
  • Milestone changed from Awaiting Review to Future Release

7 years ago

Created .diff

#2 @xkon
7 years ago

  • Keywords has-patch added; needs-patch removed

Created a diff as the original author proposed for easier access & testing.

I also run some tests with various folder configurations without seeing any problems. So probably it's good to go as well.

Best regards,

Last edited 7 years ago by xkon (previous) (diff)

This ticket was mentioned in Slack in #core by desrosj. View the logs.

7 years ago

7 years ago

Patch with unit tests

#4 @theorboman
7 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

I've added another patch with some pretty simple unit tests for this.

#5 @schlessera
7 years ago

  • Keywords close added; good-first-bug has-patch has-unit-tests removed

This bug was solved as part of #6531 and is not valid anymore for release 4.9.

#6 @dd32
7 years ago

  • Keywords close removed
  • Milestone changed from Future Release to 4.9
  • Resolution set to fixed
  • Status changed from new to closed
  • Version 4.8 deleted

This was effectively fixed through [41806]. I'm marking this as fixed in 4.9.

Note: See TracTickets for help on using tickets.